Issue
Sometime i see somebody define like this in property file:
spring.autoconfigure.exclude[0]=com.vietnam.AAutoConfiguration
spring.autoconfigure.exclude[1]=com.vietnam.BAutoConfiguration
just question: how to define a property in Spring bean to collect this config as list? in other place they said to use like this: in propery:
spring.autoconfigure.exclude=com.vietnam.AAutoConfiguration,com.vietnam.BAutoConfiguration
in spring bean
@Value("#{'${spring.autoconfigure.exclude}'.split(',')}"
But i dont like this way in case the value is long. one config per line would be easier to read and mantain
Thanks
Solution
i found the way, use @Value
will not support case i want.
We need to use @ConfigurationProperties
then Spring will collect property as list
@ConfigurationProperties(prefix = "spring.autoconfigure")
public class SpringConfig {
@Setter //lombok
private List<String> exclude;
}
Config will simple like:
spring.autoconfigure.exclude[0]=com.vietnam.AAutoConfiguration
spring.autoconfigure.exclude[1]=com.vietnam.BAutoConfiguration
Answered By - uncle bob
Answer Checked By - Katrina (JavaFixing Volunteer)