Excluding Only rabbitMqtemplate autoconfiguration in spring boot

huangapple 未分类评论55阅读模式
英文:

Excluding Only rabbitMqtemplate autoconfiguration in spring boot

问题

我已经在我的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。

注意:

我尝试过在我的yml文件中使用以下设置:

spring.autoconfigure.exclude: org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration

但这也会停止其他的bean。我只想停止嵌套类 RabbitAutoConfiguration.RabbitTemplateConfiguration 的自动配置,并且只想使用我的 SpringCloudConfiguration

英文:

I have configured RabbitMQ in my file SpringCloudConfiguration.

@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;
}

But when I'm trying to run the server, it's showing the following exception:

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.

I have to use the property "spring.main.allow-bean-definition-overriding: true" to for overriding. I don't want to use this property.
Is it possible to exclude this AutoConfiguration RabbitAutoConfiguration$RabbitTemplateConfiguration.class?

I just want to exclude RabbitTemplateConfiguration and not the entire RabbitAutoConfiguration as Spring is configuring some other beans as well.

Note:

I tried with this

`spring.autoconfigure.exclude: org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration1 in my yml file, but it stops other beans too.

I just want to stop nested class RabbitAutoConfiguration.RabbitTemplateConfiguration autoconfiguration and simply wants to use my SpringCloudConfiguration.

huangapple
  • 本文由 发表于 2020年7月28日 21:09:40
  • 转载请务必保留本文链接:https://java.coder-hub.com/63134925.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定