0

I have implemented a configuration class in Kotlin to read values from application.properties to have configurable values in the Spring Boot 2.2.2-RELEASE application.

package com.foo.bar.configuration

@ConfigurationProperties(prefix = "com.foo.bar.data.xyzmanagement")
class XyzManagementConfig {
    var pAssignment: PAssignment = PAssignment()

    var tAssignment: TAssignment = TAssignment()

    class PAssignment {
        var duration: Long = 10L
    }

    class TAssignment {
        var duration: Long = 10L
    }
}

In my application.properties I have amongst others:

# Configurable default values
com.foo.bar.data.xyzmanagement.pAssignment.duration=15
com.foo.bar.data.xyzmanagement.tAssignment.duration=15

I already have tried to annotate the main class with

@ConfigurationPropertiesScan(
    {
            "com.foo.bar.configuration"
    })

as suggested from Baeldung: Guide to @ConfigurationProperties in Spring Boot

The problem is that the value 15 from application.properties is not read but instead the default value 10L is used.

du-it
  • 2,561
  • 8
  • 42
  • 80
  • Have you added `@EnableConfigurationProperties(YourConfigProperties.class)` in your main class? – Zafar Nov 18 '20 at 22:26
  • As of Spring Boot 2.2, Spring finds and registers \@ConfigurationProperties classes via classpath scanning. Therefore, there is no need to annotate such classes with \@Component (and other meta-annotations like \@Configuration), or even use the \@EnableConfigurationProperties. I tried it anyway without success. – du-it Nov 18 '20 at 23:14
  • How is the `XyzManagementConfig` bean being used, and how are you inspecting the values in it? Are you injecting it into another class? – Scott Frederick Nov 19 '20 at 22:20
  • Yes, I intended to auto wire it in the classes that need it. – du-it Nov 19 '20 at 23:38
  • Try creating a configuration property `com.foo.bar.data.xyzmanagement.answer=42` and a field `answer: int` in your `XyzManagementConfig` to see if the problem is *really* that Spring Boot does not recognize the configuration, or that there is something fishy in these nested classes. – Honza Zidek Oct 11 '21 at 19:04
  • This way I am not able to use @ConditionalOnEnabledHealthIndicator, am I? I think it only takes exactly ONE health indicator name but not a comma separated list. Hence, I am not able to dis-/enable the indicator!?? – du-it Oct 21 '21 at 14:59

0 Answers0