I'm just experimenting with spring webflux 5.0.0 and Kotlin, and I have a problem loading the configuration from application.yml
For the basic project, I start with this spring-kotlin-functional example.
But there is only manual loading of beans and routing without any loading from the configuration files, or an example of how to implement the analogue of the @ConfigurationProperties class this way.
I am trying to accept the environment in the beans section:
data class DbConfig(
var url: String = "",
var user: String = "",
var password: String = ""
)
fun beans(): BeanDefinitionDsl = beans {
bean {
env.getProperty("db", DbConfig::class.java)
}
bean<DBConfiguration>()
//controllers
bean { StatsController(ref()) }
bean { UserController(ref()) }
bean { UserRepository(ref()) }
bean { StatsService(ref()) }
bean { Routes(ref(), ref()) }
bean("webHandler") {
RouterFunctions.toWebHandler(ref<Routes>().router(), HandlerStrategies.builder().viewResolver(ref()).build())
}
bean {
val prefix = "classpath:/templates/"
val suffix = ".mustache"
val loader = MustacheResourceTemplateLoader(prefix, suffix)
MustacheViewResolver(Mustache.compiler().withLoader(loader)).apply {
setPrefix(prefix)
setSuffix(suffix)
}
}
}
but only system properties exist in the environment
So, the question is how to load the configuration from application.yml and how to implement the @ConfigurationProperties analogue in such a functional style?
, spring -boot (, @Bean, @Repository, @Transactional ) Beans?
: github
2017-10-21
. , BeanPostProcessor. :
bean<CommonAnnotationBeanPostProcessor>()
bean<ConfigurationClassPostProcessor>()
@Configuration
, @Bean
@PostConstruct
. @ConfigurationProperties
spring-boot
, yml spring-boot-starter
..
spring-boot-starter
bean<ConfigurationPropertiesBindingPostProcessor>()
beans @ConfigurationProperties
, config application.yml . :
val resource = ClassPathResource("/application.yml")
val sourceLoader = YamlPropertySourceLoader()
val properties = sourceLoader.load("main config", resource, null)
environment.propertySources.addFirst(properties)
GenericApplicationContext
. , , spring-boot-starter
.
: