Interface EnvironmentAware
-
org.springframework.context.EnvironmentAware
- setEnvironment(Environment environment)
-
任何实现这个接口的bean将可以获得其运行的环境
setEnvironment(Environment environment)
- 设置此组件运行的环境。
使用场景
- 加载配置文件
场景一:@configration的配置类读取properties中的值
@Configuration
public class MyConfig implements EnvironmentAware {
private static Environment env;
@Override
public void setEnvironment(Environment environment) {
env=environment;
}
// ...
// todo : 读取env中的值 用来配置其他对象
}