如果在某个类里面想要使用spring的一些东西,就可以通过实现XXXAware接口告诉spring。比如在实现ApplicationContextAware接口的类中重写接扣的setApplicationContext(ApplicationContext applicationContext)就可以在Bean中使用ApplicationContext。
EnvironmentCapable这个接口可以提供Environment,所以EnvironmentCapable唯一的方法是getEnvironment()。ApplicationContext接口继承了EnvironmentCapable接口,所以具备了获取Environment的能力。
getEnvironment方法的实现是在AbstractApplicationContext中,第一次调用getEnvironment方法时会对Environment进行初始化即创建一个StandardEnvironment的实例,之后会加载两种属性源,一种是系统属性还有一种是JVM属性。
EnvironmentEnvironment接口有一个getActiveProfiles方法是获取当前环境
使用示例@Component public class SpringEnvironmentUtil implements ApplicationContextAware



