What is the method of injecting arrays into springboot application.properties files?
This article mainly introduces "what is the springboot application.properties file injection array mode". In the daily operation, I believe that many people have doubts about the springboot application.properties file injection array mode. The editor consulted all kinds of information and sorted out a simple and easy-to-use operation method. I hope it will be helpful to answer the question of "what is the springboot application.properties file injection array way?" Next, please follow the editor to study!
Application.properties file injection array
1.application.properties
Ips=192.168.0.105192.168.0.106,0:0:0:0:0:0:0:1
two。 Code
@ Value ("# {${ips} '.split (',')}") private List iplist; injects value,list and map configuration files into application.properties
Configure the values that need to be injected in the configuration file.
# single value val=10#Listlist=1,2,3,4#Mapmap= {'name':'chen',' age':'12', 'sex':' male'} # Mapmap.of.list= {\ 'KEY1': {' value1','value2'},\ 'KEY2': {' value3','value4'},\ 'KEY3': {' value5'}\} comments
Use @ PropertySource annotation to indicate the path of configuration file, and introduce multiple configuration files at the same time can use @ PropertySources annotation
PropertySource (value = {"classpath:application-left.properties"}) @ PropertySources ({@ PropertySource (value = "classpath:application.properties", encoding = "UTF-8")})
Data injection / / single numeric value, can be injected as int or String@Value ("${val}") private int val;// array @ Value ("# {${list} '.split (',')}") private List list;//map@Value ("# {${map}}") private Map map;//map of list@Value ("# {${map.of.list}}") private Map map
Test result
ten
[1, 2, 3, 4]
{name=chen, age=12, sex= male}
{KEY1= [value1, value2], KEY2= [value3, value4], KEY3= [value5]}
At this point, on the "springboot application.properties file injection array is what is the end of the study, I hope to be able to solve your doubts." The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!