I'm new to spring dependency-injection and am reaching out to learn about best practices. I would like to know if its a good design philosophy to inject classes annotated with @ConfigurationProperties
into service layer classes (annotated with @Service
). Im trying to map properties in my application.yml
to a config-class as follows -
@ConstructorBinding
@ConfigurationProperties(prefix = "application")
class ApplicationConfig(
val kafka: someDeeplyNestedType = SomeDeeplyNestedObj()
) {
// helper functions
}
I'm then injecting above config class in service layer as follows -
@Service
@EnableConfigurationProperties(ApplicationConfig::class)
class RestService(val config: ApplicationConfig) {
init {
// Reference config object
// Reference application.yml properties via config object.
}
}
I'm curious to know if I can improve upon my current implementation - not sure if its agreeable to pass configuration
classes to service-layer
classes. I'm also curious to know if theres any better approach to wiring ApplicationConfig
without needing to use EnableConfigurationProperties
annotation.