Replies: 1 comment
Solution : Use data class with default values (Recommended)import io.micronaut.context.annotation.ConfigurationProperties
@ConfigurationProperties("app.flags")
class FeatureFlagSettings {
var function1: FeatureFlagProperties = FeatureFlagProperties()
var function2: FeatureFlagProperties = FeatureFlagProperties()
var function3: FeatureFlagProperties = FeatureFlagProperties()
}
class FeatureFlagProperties {
var flag1: Boolean = false
var flag2: Boolean = false
var flag3: Boolean = false
} |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
In my Kotlin application, I have a set of feature flags. However these flags are not globally set but may different for certain business and functions and should be configured using the
application.yml. My yml looks something like this:I want to bind them using
@ConfigurationPropertiesand built the following:But I quickly realized, that the properties are not properly set. Apparently this is way of building properties only works for Java but not Kotlin. Of course I could simply copy and paste the
FeatureFlagPropertiesclass for each function with it's own class name and@ConfigurationPropertiesbut that seems not like the proper way of doing things.Is there a way to use
@ConfigurationPropertiesand reuse a class with reocurring properties? I know there is the@EachPropertyannotation but my use case is for predefined properties, not a generic collection of entries.All reactions