005SpringBoot之配置文件占位符
標簽:
SpringBoot
1、配置文件
person.lastName=李四${random.uuid}person.age=${random.int}person.birth=2017/12/15 person.boss=trueperson.maps.key1=value1 person.maps.key2=value2 person.lists=a,b,c person.dog.name=${person.lastName}_dog person.dog.age=2
PS:${random.uuid}、${random.int}都是取得random的一些方法,也可以取我们上面自定义的配置属性,比如:${person.lastName}
2、JavaBean
@PropertySource(value = {"classpath:person.properties"})@ConfigurationProperties(prefix = "person")@Componentpublic class Person { private String lastName; private Integer age; private boolean isBoss; private Date birth; private Map<String, Object> maps; private List<Object> lists; private Dog dog; ...省略getter/setter/toString()... }
3、测试类
@RunWith(SpringRunner.class)@SpringBootTestpublic class Springboot02ConfigApplicationTests { @Autowired private Person person; @Test public void contextLoads() { System.out.println(person); } }
4、输出结果
Person{lastName='李四44a6f753-30cd-4f12-a8e3-aaa42106a06f', age=-1912840149, isBoss=true, birth=Fri Dec 15 00:00:00 CST 2017, maps={key2=value2, key1=value1}, lists=[a, b, c], dog=Dog{name='李四a7c81e9a-ff3d-4c00-8ec6-f784e1ccad73_dog', age=2}}
作者:编程界的小学生
链接:https://www.jianshu.com/p/7abd807ed2ae
點擊查看更多內容
為 TA 點贊
評論
評論
共同學習,寫下你的評論
評論加載中...
作者其他優質文章
正在加載中
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦