springboot bootstrap.yml和application.yml和application.properties 加载顺利

springboot bootstrap.yml和application.yml和application.properties 加载顺利

 

原文地址https://blog.csdn.net/weixin_43931625/article/details/103628375

bootstrap.yml在application.yml之前加载,一般在spring cloud使用配置中心时使用;

bootstrap.yml同名属性会被application.yml覆盖;

application.yml在application.properties之前加载,同名属性会被application.properties覆盖


示例

导入jar包,使bootstrap.yml得配置生效

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-context</artifactId>
        <version>2.2.0.RELEASE</version>
    </dependency>

 

bootstrap.yml

server:
   port: 8081

启动应用,控制台输出

2019-12-20 11:03:50.672 INFO 20380 — [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-12-20 11:03:50.676 INFO 20380 — [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1370 ms
2019-12-20 11:03:50.936 INFO 20380 — [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService ‘applicationTaskExecutor’
2019-12-20 11:03:51.289 INFO 20380 — [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8081 (http) with context path ‘’
2019-12-20 11:03:51.296 INFO 20380 — [ main] com.example.demo.DemoApplication : Started DemoApplication in 3.264 seconds (JVM running for 6.268)
应用监听端口为8081,bootstrap.yml生效


添加application.yml

server:
   port: 8082

启动应用,控制台输出

2019-12-20 11:07:33.062 INFO 22148 — [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-12-20 11:07:33.062 INFO 22148 — [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 739 ms
2019-12-20 11:07:33.179 INFO 22148 — [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService ‘applicationTaskExecutor’
2019-12-20 11:07:33.374 INFO 22148 — [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8082 (http) with context path ‘’
2019-12-20 11:07:33.377 INFO 22148 — [ main] com.example.demo.DemoApplication : Started DemoApplication in 2.011 seconds (JVM running for 3.696)
应用监听端口为8082,application.yml覆盖bootstrap.yml的端口配置


添加application.properties

server.port=8083

启动应用,控制台输出

2019-12-20 11:11:04.004 INFO 608 — [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-12-20 11:11:04.004 INFO 608 — [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 844 ms
2019-12-20 11:11:04.149 INFO 608 — [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService ‘applicationTaskExecutor’
2019-12-20 11:11:04.316 INFO 608 — [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8083 (http) with context path ‘’
2019-12-20 11:11:04.320 INFO 608 — [ main] com.example.demo.DemoApplication : Started DemoApplication in 2.018 seconds (JVM running for 3.692)
应用监听端口为8083,application.properties覆盖前面的配置信息
————————————————

posted @ 2022-09-09 12:12  kelelipeng  阅读(407)  评论(0编辑  收藏  举报