配置文件
在配置文件中配置需要注入的值。
#单个值
val=10
#List
list=1,2,3,4
#Map<String, String>
map={'name':'chen', 'age':'12', 'sex':'男'}
#Map<String, List<String>>
map.of.list={\
'KEY1': {'value1','value2'}, \
'KEY2': {'value3','value4'}, \
'KEY3': {'value5'} \
}
注解
使用@PropertySource注解标明配置文件路径,同时引入多个配置文件可使用@PropertySources注解
@PropertySource(value = {"classpath:application-left.properties"})
@PropertySources({@PropertySource(value = "classpath:application.properties", encoding = "UTF-8")})
数据注入
//单个数值,可注入为int或String
@Value