1. Static (DI 가 잘되지 않아 env = null 인 경우, EnvironmentAware를 구현)
@Configuration
@PropertySource("classpath:my.properties")
public class MyConfig implements EnvironmentAware {
final static Environment env;
@Override
public void setEnvironment(Environment env) {
MyConfig.env = env;
}
2. Contructor DI
@Configuration
@PropertySource("classpath:my.properties")
public class MyConfig {
final Environment env;
public MyConfig(Environment env) {
this.env = env;
}
3. Setter DI
@Configuration
@PropertySource("classpath:my.properties")
public class MyConfig {
Environment env;
@Autowired
public void setEnv(Environment env) {
this.env = env;
}
※ Field DI는 권장되지 않아 사용하지 않을 예정