當(dāng)前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
Spring Boot笔记-自定义配置项默认值设置
生活随笔
收集整理的這篇文章主要介紹了
Spring Boot笔记-自定义配置项默认值设置
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
如果用動(dòng)態(tài)配置中心,如果漏了配置會(huì)很麻煩,spring boot可以設(shè)置個(gè)默認(rèn)值如下:
這個(gè)是正常的:
application.properties
test.hello=Hello WorldMyController.java
@RestController public class MyController {@Value("${test.hello}")private String value;@GetMapping("/hello")public Object hello(){return value;} }如果把a(bǔ)pplication.properties去掉:
將MyController.java改為:
@RestController public class MyController {@Value("${test.hello:test}")private String value;@GetMapping("/hello")public Object hello(){return value;} }結(jié)果是這樣:
?
?
?
總結(jié)
以上是生活随笔為你收集整理的Spring Boot笔记-自定义配置项默认值设置的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Wireshark笔记-ping,arp
- 下一篇: Spring Boot关于thymele