最代码官方
2020-12-20 11:31:56
证
Spring Boot配置@Profile注解加载不同环境的配置文件实例
项目描述
springboot启动时,可以通过参数
spring.profiles.active=prod
来加载不同的配置文件
也可以通过include参数指定加载其他的配置
spring: profiles: active: - default include: common
运行环境
jdk8+mysql+IntelliJ IDEA+maven
项目技术(必填)
spring boot
数据库文件(可选)
无
依赖包文件(可选)
maven搭建
链接:https://pan.baidu.com/s/14I37LqozknSqUXi_1jHpuw
提取码:qp4o
是否原创(转载必填原文地址)
转载https://memorynotfound.com/spring-boot-managing-profiles-profile-annotation-example/
项目截图(必填)
运行截图(必填)
. ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v1.5.3.RELEASE) 2020-12-20 11:28:50.255 INFO 1484 --- [ main] c.memorynotfound.springboot.Application : Starting Application on CIFX5T2TRH4ZE3H with PID 1484 (started by Administrator in D:\workspace-idea\memorynotfound\spring-framework\spring-boot\profiles) 2020-12-20 11:28:50.260 INFO 1484 --- [ main] c.memorynotfound.springboot.Application : The following profiles are active: common,dev 2020-12-20 11:28:50.390 INFO 1484 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@79e2c065: startup date [Sun Dec 20 11:28:50 CST 2020]; root of context hierarchy 2020-12-20 11:28:51.583 INFO 1484 --- [ main] c.memorynotfound.springboot.Application : Spring Boot - active profile: development profile 2020-12-20 11:28:51.583 INFO 1484 --- [ main] c.memorynotfound.springboot.Application : Spring Boot - Choosing Your Profile and @Profile annotation example 2020-12-20 11:28:51.583 INFO 1484 --- [ main] c.memorynotfound.springboot.Application : ApplicationProperties{name='common-profile-name', email='development@zuidaima.com'} 2020-12-20 11:28:52.062 INFO 1484 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup 2020-12-20 11:28:52.130 INFO 1484 --- [ main] c.memorynotfound.springboot.Application : Started Application in 2.812 seconds (JVM running for 4.595) . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v1.5.3.RELEASE) 2020-12-20 11:28:52.373 INFO 1484 --- [ main] c.memorynotfound.springboot.Application : Starting Application on CIFX5T2TRH4ZE3H with PID 1484 (started by Administrator in D:\workspace-idea\memorynotfound\spring-framework\spring-boot\profiles) 2020-12-20 11:28:52.373 INFO 1484 --- [ main] c.memorynotfound.springboot.Application : The following profiles are active: common,default 2020-12-20 11:28:52.385 INFO 1484 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@9ef8eb7: startup date [Sun Dec 20 11:28:52 CST 2020]; root of context hierarchy 2020-12-20 11:28:52.598 INFO 1484 --- [ main] c.memorynotfound.springboot.Application : Spring Boot - active profile: development profile 2020-12-20 11:28:52.598 INFO 1484 --- [ main] c.memorynotfound.springboot.Application : Spring Boot - Choosing Your Profile and @Profile annotation example 2020-12-20 11:28:52.598 INFO 1484 --- [ main] c.memorynotfound.springboot.Application : ApplicationProperties{name='common-profile-name', email='default@zuidaima.com'} 2020-12-20 11:28:52.641 INFO 1484 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup 2020-12-20 11:28:52.646 INFO 1484 --- [ main] c.memorynotfound.springboot.Application : Started Application in 0.457 seconds (JVM running for 5.111) . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v1.5.3.RELEASE) 2020-12-20 11:28:52.770 INFO 1484 --- [ main] c.memorynotfound.springboot.Application : Starting Application on CIFX5T2TRH4ZE3H with PID 1484 (started by Administrator in D:\workspace-idea\memorynotfound\spring-framework\spring-boot\profiles) 2020-12-20 11:28:52.770 INFO 1484 --- [ main] c.memorynotfound.springboot.Application : The following profiles are active: common,prod 2020-12-20 11:28:52.773 INFO 1484 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@75b25825: startup date [Sun Dec 20 11:28:52 CST 2020]; root of context hierarchy 2020-12-20 11:28:52.979 INFO 1484 --- [ main] c.memorynotfound.springboot.Application : Spring Boot - active profile: production profile 2020-12-20 11:28:52.979 INFO 1484 --- [ main] c.memorynotfound.springboot.Application : Spring Boot - Choosing Your Profile and @Profile annotation example 2020-12-20 11:28:52.979 INFO 1484 --- [ main] c.memorynotfound.springboot.Application : ApplicationProperties{name='common-profile-name', email='production@zuidaima.com'} 2020-12-20 11:28:53.015 INFO 1484 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup 2020-12-20 11:28:53.019 INFO 1484 --- [ main] c.memorynotfound.springboot.Application : Started Application in 0.361 seconds (JVM running for 5.484) 2020-12-20 11:28:53.024 INFO 1484 --- [ Thread-4] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@9ef8eb7: startup date [Sun Dec 20 11:28:52 CST 2020]; root of context hierarchy 2020-12-20 11:28:53.024 INFO 1484 --- [ Thread-6] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@75b25825: startup date [Sun Dec 20 11:28:52 CST 2020]; root of context hierarchy 2020-12-20 11:28:53.025 INFO 1484 --- [ Thread-2] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@79e2c065: startup date [Sun Dec 20 11:28:50 CST 2020]; root of context hierarchy 2020-12-20 11:28:53.029 INFO 1484 --- [ Thread-2] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown 2020-12-20 11:28:53.029 INFO 1484 --- [ Thread-6] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown 2020-12-20 11:28:53.028 INFO 1484 --- [ Thread-4] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown Process finished with exit code 0
注意事项(可选)
可以研究下springboot加载配置文件的机制
https://cloud.tencent.com/developer/article/1497520
猜你喜欢
请下载代码后再发表评论
文件名:profiles.zip,文件大小:8.215K
下载
- /
- /profiles
- /profiles/pom.xml
- /profiles/src
- /profiles/src/main
- /profiles/src/main/java
- /profiles/src/main/java/com
- /profiles/src/main/java/com/memorynotfound
- /profiles/src/main/java/com/memorynotfound/springboot
/profiles/src/main/java/com/memorynotfound/springboot/Application.java
/profiles/src/main/java/com/memorynotfound/springboot/ApplicationProperties.java
/profiles/src/main/java/com/memorynotfound/springboot/Configuration.java
/profiles/src/main/java/com/memorynotfound/springboot/DevelopmentConfiguration.java
/profiles/src/main/java/com/memorynotfound/springboot/ProductionConfiguration.java
- /profiles/src/main/java/com/memorynotfound/springboot
- /profiles/src/main/java/com/memorynotfound
- /profiles/src/main/java/com
- /profiles/src/main/resources
- /profiles/src/main/resources/config
- /profiles/src/main/resources/config
- /profiles/src/main/java
- /profiles/src/main
- /profiles
相关代码
- springboot demo小例子
- 原 SpringBoot入门整合开发java Web项目实例
- 证精 Springboot开发的精简博客系统
- 证 Springboot实现的图书商城系统
- 原证 springboot麦克风录制声音文件保存本地,可拓展ASR识别后返回
- 证精 SpringBoot开发非常美观的java博客系统(包含后台管理功能)
- 原证 springboot通过qq邮箱发送邮件
- 证精 Springboot开发的客户关系管理系统SpringbootCRM
- 证 SpringBoot用户登录注册简单实例
- 原 springboot入门之hello world(小白必看)
- 原 springboot入门demo实例
- 证 springboot自定义注解实现重置密码验证功能
最近下载
最近浏览
qq1357574774 LV2
2023年8月11日
845448008 LV3
2023年6月24日
szf123 LV12
2023年5月30日
海盗来了 LV20
2023年3月23日
月光橘子
2023年3月11日
暂无贡献等级
飞翔的面包片 LV12
2023年2月10日
yohohero LV1
2023年1月14日
q59200182 LV9
2023年1月1日
lewiszz LV2
2022年12月11日
fengshengtian LV8
2022年2月22日