Spring Boot 03 profile的使用
来源:互联网 发布:java html转义 编辑:程序博客网 时间:2024/05/16 15:45
在开发时,一般情况开发、测试和生产的环境都是不一样的,所以需要不同的配置文件。
配置文件目录:
application-dev.properties
test=devapplication-prod.properties
test=prodapplication-test.properties
test=test激活profile
1、
SpringApplication springApplication = new SpringApplication(App.class);springApplication.setAdditionalProfiles("dev");ConfigurableApplicationContext context = springApplication.run(args);System.out.println(context.getEnvironment().getProperty("test"));2、使用main方法的arguments参数:--spring.profiles.active=dev(如需要开启多个profile,可以使用“,”隔开)
@Profile注解
ProfileConfig.java
import org.springframework.boot.SpringBootConfiguration;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Profile;@SpringBootConfigurationpublic class ProfileConfig {@Beanpublic User createRunnable1(){System.out.println("===1===");return new User();}@Bean@Profile("dev")public User createRunnable2(){System.out.println("===2===");return new User();}@Bean@Profile("prod")public User createRunnable3(){System.out.println("===3===");return new User();}}运行
@SpringBootApplicationpublic class App {public static void main(String[] args) {SpringApplication springApplication = new SpringApplication(App.class);springApplication.setAdditionalProfiles("dev");ConfigurableApplicationContext context = springApplication.run(args);System.out.println(context.getEnvironment().getProperty("test"));}}结果
若是注解在配置类上,则配置类里面的bean容器全部都会生成。
阅读全文
0 0
- Spring Boot 03 profile的使用
- Spring Boot Profile使用
- Spring-Boot使用profile来配置不同环境的配置文件
- spring boot 使用profile来分区配置
- spring-boot使用profile环境切换
- spring boot 使用profile来分区配置
- spring boot 使用profile来分区配置
- 06-maven的profile和Spring boot 的profile整合
- Spring Boot的Profile切换方式
- Spring Boot Profile 配置
- spring profile的基本使用
- spring @profile注解的使用
- spring @profile注解的使用
- Spring Boot Profile配置实例
- spring boot集成maven profile
- 集成maven和Spring boot的profile功能
- Maven与Spring Boot的profile功能集成
- [Spring Boot 系列] 集成maven和Spring boot的profile功能
- 自动把动态的jsp页面(或静态html)生成PDF文档,并且上传至服务器
- 在UBUNTU下安装运行eclipse显示找不到jre,一大串英文。java -version显示正确。配置正确。
- 每个程序员都应该了解的十一句话
- Android(常用)主流UI开源库整理
- 6 OF 100DAYS
- Spring Boot 03 profile的使用
- MSP430定时/计数器TimerA的使用详解(一)
- make: *** [.build_release/lib/libcaffe.so.1.0.0-rc3] 错误 1 问题解决
- openoffice java实现word转PDF
- 统计学习方法 6-逻辑斯谛回归与最大熵模型
- 测试小故事44:客观
- bitTiger讲解:Leetcode如何刷(经验分享)
- [机器学习实战] Ubuntu 16.04 + NVIDIA 384 + OpenCV 3.1.0 + CUDA 8.0 + cuDNN 5.1 踩坑记录
- Prim和Kruskal求最小生成树