最代码官方
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使用不指定Maven parent pom来创建可执行的spring boot项目
- Spring Boot整合jsp做为显示层的hello world实例
- Swagger的简单案例,适合初级者学习使用
- springboot2.x+mybatis-plus+jsp+jpa简单增删改查实例(仅供学习)
- Spring Boot整合thymeleaf做为显示层的hello world实例
- Spring Boot整合Freemarker实现文件上传项目实例
- SpringBoot入门整合开发java Web项目实例
- Spring Boot整合SpringFox Swagger2实现REST API增删改查项目实例
- Spring Boot整合VueJS+spring data jpa实现待办事项TODO项目实例
请下载代码后再发表评论
文件名: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使用不指定Maven parent pom来创建可执行的spring boot项目
- 证 Spring Boot整合jsp做为显示层的hello world实例
- 原证 Swagger的简单案例,适合初级者学习使用
- 原证 springboot2.x+mybatis-plus+jsp+jpa简单增删改查实例(仅供学习)
- 证 Spring Boot整合thymeleaf做为显示层的hello world实例
- 证 Spring Boot整合Freemarker实现文件上传项目实例
- 原 SpringBoot入门整合开发java Web项目实例
- 证 Spring Boot整合SpringFox Swagger2实现REST API增删改查项目实例
- 证 Spring Boot整合VueJS+spring data jpa实现待办事项TODO项目实例
- 证精 基于spring boot+spring data jpa+bootstrap的企业级进销存管理系统
- 证精 spring boot+mybatis开发java web网页版电子商城网站(适合spring boot初学者学习)


yohohero LV1
1月14日
q59200182 LV9
1月1日
lewiszz LV2
2022年12月11日
fengshengtian LV8
2022年2月22日
hsc456 LV2
2021年10月8日
park96323
2021年7月23日
暂无贡献等级
15816654419 LV1
2021年6月29日
lbwnblbwnblbwnb LV7
2021年6月21日
风间千月 LV13
2021年6月2日
skycrawler LV6
2021年5月28日