Spring Boot中的application.properties
配置文件
test.key: value
test.array1: aaa,bbb,ccc
test.array2:
test.set: 111,222,333,111
test.map1: {"name": "zhangsan", sex: "male"}
使用@value注解读取配置文件的信息
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
@Service
public class AliaPay2 implements IPayMethod {&#64;Value("${test.key}")private String value;&#64;Value("${test.array1}")private String[] testArray1;&#64;Value("${test.array1}")private static String[] testArrayError1;&#64;Value("${test.array1}")private List<String> testArrayError2;&#64;Value("#{&#39;${test.array1:}&#39;.split(&#39;,&#39;)}")private List<String> testList;&#64;Value("#{&#39;${test.array1:}&#39;.empty ? null : &#39;${test.array1:}&#39;.split(&#39;,&#39;)}")private List<String> testList1;&#64;Value("${test.array2}")private String[] testArray2;&#64;Value("${test.array3:}")private String[] testArray3;&#64;Value("#{&#39;${test.set:}&#39;.empty ? null : &#39;${test.set:}&#39;.split(&#39;,&#39;)}")private Set<Integer> testSet;&#64;Value("#{${test.map1}}")private Map<String,String> map1;
}