带有Spring引导的Spring JMS,冲突的bean

时间:2016-05-09 07:53:18

标签: spring spring-boot spring-jms

我正在使用Spring启动创建Spring JMS侦听器,但我一直收到此错误: -

org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [javax.jms.ConnectionFactory] is defined: expected single matching bean but found 3: queueConnectionFactory,queueConnectionFactoryExtra,targetConnectionFactory
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1126)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545)

无论我阅读它是使用@Qualifier注释解决的,但这对我来说似乎不起作用,请帮忙。以下是我的课程: -

@Configuration
public class ListenerContainer{ 


@SuppressWarnings("rawtypes")
@Qualifier("queueConnectionFactory")
@Bean(name="planListenerContainerFactoryExtra")
public JmsListenerContainerFactory jmsListenerContainerFactory(@Qualifier("queueConnectionFactory") ConnectionFactory queueConnectionFactory,@Qualifier("queue") MQQueue queue, ErrorHandler errorHandler) {
    DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
    factory.setConnectionFactory(queueConnectionFactory);
    factory.setErrorHandler(errorHandler);

    return factory;
}




@Qualifier("targetConnectionFactory")
@Bean(name="queueConnectionFactory")
public ConnectionFactory queueConnectionFactory(@Qualifier("targetConnectionFactory")  MQQueueConnectionFactory targetConnectionFactory) {
    CachingConnectionFactory queueConnectionFactory = new CachingConnectionFactory();
    ....
    return queueConnectionFactory;

}

@Bean(name="targetConnectionFactory")
public MQQueueConnectionFactory targetConnectionFactory() {
    MQQueueConnectionFactory targetConnectionFactory = new MQQueueConnectionFactory();

    return targetConnectionFactory;

}

@Bean(name="queue")
public MQQueue queue() {
    MQQueue queue = new MQQueue();
    .....
    return queue;

}

}

0 个答案:

没有答案