BeanRegistrarDsl

Contract for registering programmatically beans.

Typically imported with an @Import annotation on @Configuration classes.

@Configuration
@Import(MyBeanRegistrar::class)
class MyConfiguration {
}

In Kotlin, a bean registrar is typically created with a BeanRegistrarDsl to register beans programmatically in a concise and flexible way.

class MyBeanRegistrar : BeanRegistrarDsl({
registerBean<Foo>()
registerBean(
name = "bar",
prototype = true,
lazyInit = true,
description = "Custom description") {
Bar(bean<Foo>())
}
profile("baz") {
registerBean { Baz("Hello World!") }
}
})

Author

Sebastien Deleuze

Since

7.0

Constructors

Link copied to clipboard
constructor(init: BeanRegistrarDsl.() -> Unit)

Types

Link copied to clipboard

Context available from the bean instance supplier designed to give access to bean dependencies.

Properties

Link copied to clipboard
lateinit var env: Environment

The environment that can be used to get the active profile or some properties.

Functions

Link copied to clipboard
fun profile(expression: String, init: BeanRegistrarDsl.() -> Unit)

Apply the nested block if the given profile expression matches the active profiles.

Link copied to clipboard
fun register(registrar: BeanRegistrar)

Register beans using the given BeanRegistrar.

open override fun register(registry: BeanRegistry, env: Environment)
Link copied to clipboard
inline fun <T : Any> registerBean(autowirable: Boolean = true, backgroundInit: Boolean = false, description: String? = null, fallback: Boolean = false, infrastructure: Boolean = false, lazyInit: Boolean = false, order: Int? = null, primary: Boolean = false, prototype: Boolean = false): String
inline fun <T : Any> registerBean(name: String, autowirable: Boolean = true, backgroundInit: Boolean = false, description: String? = null, fallback: Boolean = false, infrastructure: Boolean = false, lazyInit: Boolean = false, order: Int? = null, primary: Boolean = false, prototype: Boolean = false)

Register a bean from the given bean class, which will be instantiated using the related resolvable constructor if any.

inline fun <T : Any> registerBean(autowirable: Boolean = true, backgroundInit: Boolean = false, description: String? = null, fallback: Boolean = false, infrastructure: Boolean = false, lazyInit: Boolean = false, order: Int? = null, primary: Boolean = false, prototype: Boolean = false, crossinline supplier: BeanRegistrarDsl.SupplierContextDsl<T>.() -> T): String

inline fun <T : Any> registerBean(name: String, autowirable: Boolean = true, backgroundInit: Boolean = false, description: String? = null, fallback: Boolean = false, infrastructure: Boolean = false, lazyInit: Boolean = false, order: Int? = null, primary: Boolean = false, prototype: Boolean = false, crossinline supplier: BeanRegistrarDsl.SupplierContextDsl<T>.() -> T)

Register a bean from the given bean class, which will be instantiated using the provided supplier.