spring-framework / org.springframework.context.support / BeanDefinitionDsl

BeanDefinitionDsl

open class BeanDefinitionDsl : ApplicationContextInitializer<GenericApplicationContext>

Class implementing functional bean definition Kotlin DSL.

Types

Autowire

enum class Autowire

Autowire enum constants.

Scope

enum class Scope

Scope enum constants.

Constructors

<init>

BeanDefinitionDsl(init: BeanDefinitionDsl.() -> Unit, condition: (ConfigurableEnvironment) -> Boolean = { true })

Create a new bean definition DSL.

Properties

context

lateinit var context: GenericApplicationContext

Access to the context for advanced use-cases.

env

val env: ConfigurableEnvironment

Shortcut for context.environment

Functions

bean

fun <T : Any> bean(name: String? = null, scope: Scope? = null, isLazyInit: Boolean? = null, isPrimary: Boolean? = null, autowireMode: Autowire = Autowire.CONSTRUCTOR, isAutowireCandidate: Boolean? = null): Unit

Declare a bean definition from the given bean class which can be inferred when possible.

fun <T : Any> bean(name: String? = null, scope: Scope? = null, isLazyInit: Boolean? = null, isPrimary: Boolean? = null, autowireMode: Autowire = Autowire.NO, isAutowireCandidate: Boolean? = null, function: () -> T): Unit

Declare a bean definition using the given supplier for obtaining a new instance.

environment

fun environment(condition: ConfigurableEnvironment.() -> Boolean, init: BeanDefinitionDsl.() -> Unit): Unit

Take in account bean definitions enclosed in the provided lambda only when the specified environment-based predicate is true.

initialize

open fun initialize(context: GenericApplicationContext): Unit

Register the bean defined via the DSL on the provided application context.

profile

fun profile(profile: String, init: BeanDefinitionDsl.() -> Unit): Unit

Take in account bean definitions enclosed in the provided lambda only when the specified profile is active.

ref

fun <T : Any> ref(name: String? = null): T

Get a reference to the bean by type or type + name with the syntax ref<Foo>() or ref<Foo>("foo"). When leveraging Kotlin type inference it could be as short as ref() or ref("foo").