当前位置:
首页 >
前端技术
> javascript
>内容正文
javascript
Spring Boot笔记-自定义配置项默认值设置
生活随笔
收集整理的这篇文章主要介绍了
Spring Boot笔记-自定义配置项默认值设置
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
如果用动态配置中心,如果漏了配置会很麻烦,spring boot可以设置个默认值如下:
这个是正常的:
application.properties
test.hello=Hello WorldMyController.java
@RestController public class MyController {@Value("${test.hello}")private String value;@GetMapping("/hello")public Object hello(){return value;} }如果把application.properties去掉:
将MyController.java改为:
@RestController public class MyController {@Value("${test.hello:test}")private String value;@GetMapping("/hello")public Object hello(){return value;} }结果是这样:
总结
以上是生活随笔为你收集整理的Spring Boot笔记-自定义配置项默认值设置的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: Wireshark笔记-ping,arp
- 下一篇: Spring Boot关于thymele