java - 在 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。
解决方案
推荐阅读
- php - 如何在 Laravel 中使用用户输入值从刀片模板文件的部分制作 PDF 文件
- stdout - 在 Windows 中将 libvips CLI 输出通过管道传输到标准输出
- excel - Excel 公式 - 有没有办法在更改为下一个连续查询单元格之前对第 n 个单元格的相同查询单元格执行 if 语句
- docker - 运行 apk add --update --no-cache py3-arrow not wokring in alpine docker image
- javascript - 我如何获得输入框的值
- javascript - 如何使用 react.js 获取格式 dd/MM/yyyy?
- string - 在 VB.NET 中将可为空的双精度变量转换为字符串
- python - 如何告诉 SymPy 变量是时间的函数?
- kotlin - 如何使用 kotlin 和 refelction 迭代嵌套数据类
- postgresql - 通过复合键删除超过限制的记录