@PropertySource注解根据不同环境动态加载自定义配置文件

1、自定义配置文件common-as-dev.properties

stu.name=zhangsan
stu.age=18
stu.sex=man

2、pom里配置环境


			as-dev
			
				8081
				/dev
				as-dev
			
			
			
				true
			
		
		

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;

 

你可能感兴趣的:(spring)