gpt4 book ai didi

java - 多连接工厂

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:19:42 24 4
gpt4 key购买 nike

我正在使用 spring boot 并设置多个连接工厂(pooled 和 jms)。我遇到的问题是它似乎试图将它们 Autowiring 到 javax.jms.ConnectionFactory 中的同一个对象。所以它导致了这个异常:

Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.jms.ConnectionFactory org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration.connectionFactory; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [javax.jms.ConnectionFactory] is defined: expected single matching bean but found 2: jmsConnectionFactory,pooledConnectionFactory
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
... 38 more
Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [javax.jms.ConnectionFactory] is defined: expected single matching bean but found 2: jmsConnectionFactory,pooledConnectionFactory
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1054)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533)
... 40 more

这是我正在使用的配置:

<bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="***" />
</bean>
<bean id="pooledConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory" init-method="start" destroy-method="stop">
<property name="maxConnections" value="10" />
<property name="connectionFactory" ref="jmsConnectionFactory" />
</bean>
<bean id="jmsConfig"
class="org.apache.camel.component.jms.JmsConfiguration">
<property name="connectionFactory" ref="pooledConnectionFactory"/>
<property name="acknowledgementModeName" value="CLIENT_ACKNOWLEDGE"/>
<property name="concurrentConsumers" value="11"/>
<property name="maxConcurrentConsumers" value="11"/>
</bean>
<bean id="activemq"
class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="configuration" ref="jmsConfig"/>
</bean>

我假设问题是这两个类都实现了 javax.jms.ConnectionFactory 类,然后它们通过 org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration 中的 ConnectionFactory Autowiring 。我在这里遗漏了什么吗,我们将不胜感激任何帮助?

最佳答案

您可以在其中一个连接工厂 bean 上设置 primary=true

关于java - 多连接工厂,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30355984/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com