I am new to Spring Boot. Currently, I am trying to create a POJO class (SystemProperties.class) to read the value in a properties file (parameter.properties separate from application.properties but still under the same directory /src/main/resources. The issue happens when I am using the @ConstructorBinding in the class in order for it to be immutable.
- @ConstructorBinding needs to be used with @EnableConfigurationProperties or @ConfigurationPropertiesScan.
- @ConfigurationPropertiesScan will ignore @Configuration annotation which is needed when using @PropertySource to specify external
*.properties file.
A) SystemProperties.class
@Configuration
@PropertySource("classpath:parameter.properties")
@ConstructorBinding
@ConfigurationProperties(prefix = "abc")
public class SystemProperties {
private final String test;
public SystemProperties (
String test) {
this.test = test;
}
public String getTest() {
return test;
}
B) parameter.properties
abc.test=text1
I have tried to remove the @PropertySource annotation but the value cannot be retrieved unless it is from the application.properties. Any help is greatly appreciated!