最代码官方
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
猜你喜欢
- Spring Boot演示@ConfigurationProperties标注实现自定义配置属性的实例
- Spring Boot学习(二)之属性配置文件详解 博客代码
- Spring Boot创建自定义Banner.txt实例
- spring boot+mybatis+mysql基础配置实现部门数据增加查询更新功能
- Spring Boot整合VueJS+spring data jpa实现待办事项TODO项目实例
- SpringBoot+Maven+Echarts实现实时展示CPU内存硬盘性能
- spring boot使用不指定Maven parent pom来创建可执行的spring boot项目
- Spring Boot整合Freemarker实现文件上传项目实例
- Spring Boot整合VueJS+spring data jpa实现RESTful API实例
- Spring Boot Actuator 2.3.4.RELEASE新版本实现自定义端点信息的配置实例
- Spring Boot整合Apache ActiveMQ实现发送消息的实例
- Springboot+Mybatis+maven+layui开发简单的学习实例
请下载代码后再发表评论
文件名: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

- 证 Spring Boot创建自定义Banner.txt实例
- 证 Spring Boot演示@ConfigurationProperties标注实现自定义配置属性的实例
- 原证 spring boot+mybatis+mysql基础配置实现部门数据增加查询更新功能
- 证 Spring Boot整合VueJS+spring data jpa实现待办事项TODO项目实例
- 原证精 SpringBoot+Maven+Echarts实现实时展示CPU内存硬盘性能
- 证 spring boot使用不指定Maven parent pom来创建可执行的spring boot项目
- 证 Spring Boot整合Freemarker实现文件上传项目实例
- 原证 Spring Boot整合VueJS+spring data jpa实现RESTful API实例
- 证 Spring Boot Actuator 2.3.4.RELEASE新版本实现自定义端点信息的配置实例
- 证 Spring Boot整合Apache ActiveMQ实现发送消息的实例
- 原证 Springboot+Mybatis+maven+layui开发简单的学习实例
- 证 Spring Boot整合SpringFox Swagger2实现REST API增删改查项目实例


qq1357574774 LV1
8月11日
845448008 LV3
6月24日
szf123 LV11
5月30日
海盗来了 LV20
3月23日
月光橘子
3月11日
暂无贡献等级
飞翔的面包片 LV12
2月10日
yohohero LV1
1月14日
q59200182 LV9
1月1日
lewiszz LV2
2022年12月11日
fengshengtian LV8
2022年2月22日