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

BeanDefinitionDsl

open class BeanDefinitionDsl : ApplicationContextInitializer<GenericApplicationContext>

Class implementing functional bean definition Kotlin DSL.

Types

Role

enum class Role

Role 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

env

val env: ConfigurableEnvironment

Shortcut for context.environment

Functions

bean

fun <T : Any> bean(name: String? = null, scope: BeanDefinitionDsl.Scope? = null, isLazyInit: Boolean? = null, isPrimary: Boolean? = null, isAutowireCandidate: Boolean? = null, initMethodName: String? = null, destroyMethodName: String? = null, description: String? = null, role: BeanDefinitionDsl.Role? = 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: BeanDefinitionDsl.Scope? = null, isLazyInit: Boolean? = null, isPrimary: Boolean? = null, isAutowireCandidate: Boolean? = null, initMethodName: String? = null, destroyMethodName: String? = null, description: String? = null, role: BeanDefinitionDsl.Role? = 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.

provider

fun <T : Any> provider(): ObjectProvider<T>

Return an provider for the specified bean, allowing for lazy on-demand retrieval of instances, including availability and uniqueness options.

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").