Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

296
Vistas
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 Respuestas
Responde la pregunta

0

You can try use:

@Configuration
@Import({ConsumerBindingConfiguration.class})
public class ConsumerConfiguration
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda