1、自定义配置文件common-as-dev.properties
stu.name=zhangsan
stu.age=18
stu.sex=man
2、pom里配置环境
<profile>
<id>as-dev</id>
<properties>
<port>8081</port>
<ctx>/dev</ctx>
<env>as-dev</env>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
3、application.properties里引用环境
spring.profiles.active=@env@
server.port=@port@
server.servlet.context-path=@ctx@
4、@PropertySource加载
@PropertySource("classpath:/common-${spring.profiles.active}.properties")
@Configuration
public class LoadProperties {
}
5、@Value注解引用
@Value("${stu.name}")
private String stuName;