SpringBoot的配置优先级,一个具体的练习例子
SpringBoot里的官方文档叫做Externalized Configuration:
优先级依次如下:
(1) Devtools global settings properties in the $HOME/.config/spring-boot folder when devtools is active.
(2) @TestPropertySource annotations on your tests.
(3) properties attribute on your tests. Available on @SpringBootTest and the test annotations for testing a particular slice of your application.
(4) Command line arguments.
(5) Properties from SPRING_APPLICATION_JSON (inline JSON embedded in an environment variable or system property).
(6) ServletConfig init parameters.
(7) ServletContext init parameters.
(8) JNDI attributes from java:comp/env.
(9) Java System properties (System.getProperties()).
(10) OS environment variables.
(11) A RandomValuePropertySource that has properties only in random.*.
(12) Profile-specific application properties outside of your packaged jar (application-{profile}.properties and YAML variants).
(13) Profile-specific application properties packaged inside your jar (application-{profile}.properties and YAML variants).
(14) Application properties outside of your packaged jar (application.properties and YAML variants).
(15) Application properties packaged inside your jar (application.properties and YAML variants).
(16) @PropertySource annotations on your @Configuration classes. Please note that such property sources are not added to the Environment until the application context is being refreshed. This is too late to configure certain properties such as logging. and spring.main. which are read before refresh begins.
(17) Default properties (specified by setting SpringApplication.setDefaultProperties).
做个实验,在run as configuration里,program argument设置为server.port=8001,
Environment环境变量设置为server.port=8002.
在SpringBoot项目内部的Application.properties文件设置成8000:
最后运行时,生效的端口是环境变量设置进去的8002:
在shell里使用set命令设置环境变量,也能按照期望的方式工作:
本文来自云栖社区合作伙伴“汪子熙”,了解相关信息可以关注微信公众号"汪子熙"。
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
SpringBoot里slf4j日志功能的默认实现
本文是这篇教程的学习笔记:https://www.springboottutorial.com/logging-with-spring-boot-logback-slf4j-and-log4j我有一个最简单的SpringBoot应用,其pom.xml里的依赖定义如下: 上图看到很多Starter,比如Spring-boot-starter-data-redis, Spring-boot-starter-web等等。这些Starter都包含了一个spring-boot-starter, 而这个starter又包含了一个实现logging的starter,叫做spring-boot-starter-logging. 也就是说,如果我们使用SpringBoot,无需再导入额外的配置,就能使用日志功能了。 SpringBoot slf4j的默认实现是logback,默认输出是到控制台console: As you can see the default logging framework is Logback with SLF4j as implementation.By default, a...
- 下一篇
使用SAP WebIDE创建开发Java应用,并且在浏览器里调试
打开SAP WebIDE,新建一个项目,选择New from template,基于Multi-Target Application模板创建: 项目创建完毕后,右键选择New->Java Module: 新建的这个Java module同样要基于模板选择一个类型:这里我选择Simple Web Application: Run->Run as Java Application: 这个操作会自动把该Java应用部署到SAP Cloud Platform的CloudFoundry环境上去,生成一个外界可以访问的url: 我们回到SAP云平台,看到这个自动被部署的Java应用: 能按照我们期望的方式工作: WebIDE里同样可以进行单步调试: 本文来自云栖社区合作伙伴“汪子熙”,了解相关信息可以关注微信公众号"汪子熙"。
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- Hadoop3单机部署,实现最简伪集群
- CentOS7,CentOS8安装Elasticsearch6.8.6
- CentOS7安装Docker,走上虚拟化容器引擎之路
- CentOS7编译安装Gcc9.2.0,解决mysql等软件编译问题
- Windows10,CentOS7,CentOS8安装MongoDB4.0.16
- CentOS7编译安装Cmake3.16.3,解决mysql等软件编译问题
- SpringBoot2整合Redis,开启缓存,提高访问速度
- CentOS6,7,8上安装Nginx,支持https2.0的开启
- Linux系统CentOS6、CentOS7手动修改IP地址
- CentOS6,CentOS7官方镜像安装Oracle11G