Is it possible to enforce ordering of two @Configuration classes?
Case I have is that in one of the configuration classes (ConsumerConfiguration) I declare @Bean of SimpleMessageListenerContainer:
@Bean
public SimpleMessageListenerContainer container(ConnectionFactory connectionFactory) {
SimpleMessageListenerContainer container =
new SimpleMessageListenerContainer(connectionFactory);
container.setQueueNames("queue");
return container;
}
which is supposed to listen to a queue. (It's a part of Spring Integration + AMQP project)
My assumption is that all Rabbit components would be created beforehand and I normally don't want to declare them in Java. However, for dev profile I would like the application to create them for me, hence another @Configuration class:
@Configuration
@RequiredArgsConstructor
@Profile("dev")
public class ConsumerBindingConfiguration {
@Bean
public Exchange exchange() {
return ExchangeBuilder.topicExchange("exchange")
.durable()
.build();
}
@Bean
Queue queue() {
return QueueBuilder.durable("queue")
.build();
}
@Bean
Binding binding() {
return BindingBuilder.bind(queue())
.to(exchange())
.with("key")
.noargs();
}
}
Unfortunately, when I run the application, the ConsumerConfiguration class is being run first. Seems that @Order annotation is not working for @Configuration classes. I saw @DependsOn annotation, but I can't use it in my case (for any profile different than dev I don't want to declare the queue).
You can try use:
@Configuration
@Import({ConsumerBindingConfiguration.class})
public class ConsumerConfiguration