Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

295
Visualizações
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).

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You can try use:

@Configuration
@Import({ConsumerBindingConfiguration.class})
public class ConsumerConfiguration
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda