我已经在文件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"
进行覆盖。我不想使用此属性。
是否可以排除此自动配置RabbitAutoConfiguration$RabbitTemplateConfiguration.class
?
我只想排除 RabbitTemplateConfiguration 而不是整个 RabbitAutoConfiguration ,因为Spring也正在配置其他一些bean。
注意:
我尝试过
在我的yml文件中排除了spring.autoconfigure.exclude:org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration1,但它也停止了其他bean。
我只想停止嵌套类RabbitAutoConfiguration.RabbitTemplateConfiguration
自动配置,只想使用我的 SpringCloudConfiguration 。