在application.properties中配置spring.profiles.active,在pom.xml中配置profiles标签即,
1.配置文件内容:在resources目录下:
默认:application.properties
spring.profiles.active=@profiles.active@
开发环境:application-dev.properties
name=dev
生产环境:application-prod.properties
name=prod
测试环境:application-test.properties
name=test
在application.yml根据spring.profiles.active配置启用指定配置文件生效
2.pom.xml文件添加profiles如下:3.测试代码:dev true dev test test prod prod
@RestController
public class Controller {
@Value("${name}")
private String name;
@RequestMapping(value = {"/hello"},method = RequestMethod.GET)
public String say(){
return name;
}
}
demo2
在application.properties中配置spring.profiles.active,在pom.xml中无需配置profiles标签,配置了也不影响。
在resources目录下:
默认:application.properties
共用配置:application-common.properties
开发环境:application-dev.properties
生产环境:application-prod.properties
测试环境:application-test.properties
在application.properties根据spring.profiles.active配置启用指定配置文件生效
在application.properties配置:
spring.profiles.active=dev,common
无需配置pom.xml。



