How can I convince Spring Boot to consider values from application.properties in my configuration class?

293 views Asked by At

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.

0

There are 0 answers