Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

293
Views
Ordering of Spring `@Configuration` classes

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).

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can try use:

@Configuration
@Import({ConsumerBindingConfiguration.class})
public class ConsumerConfiguration
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!