I have to read a few string array variables from properties file of my spring-boot project.I have already created a class with getter and setter methods for the arrays.I don't know how to get the values of those string array variables from the property.yml file using java 1.8
Asked
Active
Viewed 2,144 times
0
-
1see https://stackoverflow.com/a/41462567/3560866 – reflexdemon Nov 14 '19 at 15:53
1 Answers
1
Using @Value
In your .yaml
:
myPropertiesList: item1, item2
or
myPropertiesList: >
item1,
item2
In your Java class:
@Value("${myPropertiesList}")
String[] myPropertiesArray;
or in SpringBoot2:
@Value("${myPropertiesList}")
List<String> myPropertiesList;
Using @ConfigurationProperties
In your .yaml
:
myPrefix.myPropertiesList: item1, item2
Configuration class:
@Configuration
@ConfigurationProperties(prefix = "myPrefix")
public class ConfigProperties {
private List<String> myPropertiesList;
}
and add the following to your SpringBoot configuration:
@EnableConfigurationProperties(ConfigProperties.class)

Babyburger
- 1,730
- 3
- 19
- 32