idea手动切换开发与生产环境
一、maven配置开发与生产环境
<profiles>
<profile>
<id>dev</id>
<properties>
<spring.profiles.active>dev</spring.profiles.active>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>pro</id>
<properties>
<spring.profiles.active>pro</spring.profiles.active>
</properties>
</profile>
</profiles>
二、maven+springboot配置
application.properties文件配置:
spring.profiles.active=@spring.profiles.active@
三、使用@Profile注解
@Profile:匹配active参数,动态加载内部配置
@Bean
@Profile("dev")
public String initDevEnv(){
System.out.println("=========这是测试环境==========");
return null;
}
@Bean
@Profile("pro")
public String initProEnv(){
System.out.println("=========这是生产环境==========");
return null;
}