Spring – @ConfigurationProperties classes returning null

By

in

Posted

Tags:

Updated

If you’re working with some Spring projects, you probably tried to make a @ConfigurationProperties annotated class already and it’s giving nulls, your configuration also looks something like this:

@ConfigurationProperties(prefix = "some.prefix")
public class ConfigurationProperties {
private String[] interestingValue;
}

Solution: You need getters and setter methods :), luckily lombok has an easy way of doing this: @Data

One line change:
@Data
@ConfigurationProperties(prefix = "some.prefix")
public class ConfigurationProperties {
private String[] interestingValue;
}

Also make sure to add @EnableConfigurationProperties(ConfigurationProperties.class) to your application class.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *