下面这个类能成功注入Environment吗?为什么我的是null
@Configuration
public class PropertyConfigurer {
@Autowired
private Environment env;
public String getProperty(String name) {
return env.getProperty(name);
}
}
修改成如下就可以了,我就是想知道是不是必须通过实现EnvironmentAware才能注入Environment
@Configuration
public class PropertyConfigurer implements EnvironmentAware{
// @Autowired
private static Environment env;
public static String getProperty(String name) {
return env.getProperty(name);
}
@Override
public void setEnvironment(Environment environment) {
env=environment;
}
}