首页 > 解决方案 > 在 Spring Boot 中仅排除 rabbitMqtemplate 自动配置

问题描述

我已经在我的文件 SpringCloudConfiguration 中配置了 RabbitMQ。

@Bean
@ConditionalOnProperty(name={"gssp.amqp.enabled", "rabbitmq.addresses"}, matchIfMissing = false)
RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory, MessageConverter jsonMessageConverter) {
    RabbitTemplate template = new RabbitTemplate(connectionFactory);
    template.setMessageConverter(jsonMessageConverter);
    template.afterPropertiesSet();
    return template;
}

但是当我尝试运行服务器时,它显示以下异常:

The bean 'rabbitTemplate', defined in class path resource [org/springframework/boot/autoconfigure/amqp/RabbitAutoConfiguration$RabbitTemplateConfiguration.class], could not be registered. A bean with that name has already been defined in class path resource [com/metlife/gssp/spring/configuration/SpringCloudConfiguration.class] and overriding is disabled.

我必须使用该属性"spring.main.allow-bean-definition-overriding: true"来覆盖。我不想使用这个属性。是否可以排除此 AutoConfiguration RabbitAutoConfiguration$RabbitTemplateConfiguration.class

我只想排除RabbitTemplateConfiguration而不是整个RabbitAutoConfiguration,因为 Spring 也在配置其他一些 bean。

笔记:

我试过这个

`spring.autoconfigure.exclude: org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration1 在我的 yml 文件中,但它也会停止其他 bean。

我只想停止嵌套类RabbitAutoConfiguration.RabbitTemplateConfiguration 自动配置,只想使用我的SpringCloudConfiguration

标签: javarabbitmqspring-cloud-config

解决方案


推荐阅读