Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the method of injecting arrays into springboot application.properties files?

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report