카테고리 없음2016. 8. 23. 18:15
반응형


클래스에 EnvironmentAware 상속 받은다음에 Override setEnvironment 해주면 됩니다.

시점때문에 생기는 문제네요..



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
@Configuration
@PropertySource("classpath:myProperties.properties")
public class MyConfiguration implements EnvironmentAware {
 
    private Environment environment;
 
    @Override
    public void setEnvironment(final Environment environment) {
        this.environment = environment;
    }
 
    public void myMethod() {
        final String myPropertyValue = environment.getProperty("myProperty");
        // ...
    }
 
}
cs



1
2
3
4
5
6
7
8
9
10
public class SystemLogApplication  implements EnvironmentAware{
 
@Autowired
private static Environment env;
 
@Override
    public void setEnvironment(Environment environment) {
        // TODO Auto-generated method stub
        this.env = environment;
    } 
cs


Posted by 1010