To use @ConfigurationProperties
annotation one must create a class with getters and setters like that:
@ConfigurationProperties(prefix = "some")
public class PropertiesConfig {
private boolean debug;
public boolean isDebug() {
return debug;
}
public void setDebug(boolean debug) {
this.debug = debug;
}
}
But this leads to the situation when somebody is tempted to modify this value by calling:
@Autowire
private PropertiesConfig config;
//....
config.setDebug(true);
Is there a way to create @ConfigurationProperties
annotated classes without setters and external parser/reader classes?
Not possible out of of the box.
@ConfigurationProperties
beans have to have standard getters and setters. You might want to consider the approach described in this answer: Immutable @ConfigurationPropertiesOr something like this: