Configuration Condition
조건에 따라 환경을 설정할 수 있다.
RabbitMQ를 사용하는 서버와 사용하지 않는 서버의 환경을 달리 설정하는데 적용했다.
- Example
amqp.enabled 프로퍼티로 amqp 사용여부를 판단한다.
amqp를 사용하는 경우, 해당 클래스에 정의한 빈들을 등록한다.
amqp를 사용하지 않는 경우, 빈을 등록하지 않는다.
@Configuration
@Conditional(AmqpConfig.Condition.class)
public class AmqpConfig {
@Autowired
private Environment env;
public static class Condition implements ConfigurationCondition {
@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
return context.getEnvironment().getProperty("amqp.enabled", Boolean.class);
}
@Override
public ConfigurationPhase getConfigurationPhase() {
return ConfigurationPhase.PARSE_CONFIGURATION;
}
}
// @Bean
}
컨텍스트에 특정 빈이 등록되어 있는가? 조건 등으로도 사용할 수 있다.
'Development > Spring' 카테고리의 다른 글
JSR-303 Annotation Customizing (0) | 2019.01.07 |
---|---|
DatabaseConfiguration 적용 (0) | 2018.08.17 |
multiple 'X-Frame-Options' headers with conflicting 에러 (0) | 2017.12.15 |
비동기 메소드 HttpServletRequest 에러 (0) | 2017.12.03 |
비동기 어노테이션 (0) | 2017.11.25 |