Hi,

I am trying to connect to WMQ using UserName and password. As per one of the
posts in the User group, I tried the below code for creating a wmq component

@Bean
    MQQueueConnectionFactory jmsConnectionFactory()
    {
        jmsConnectionFactory = new MQQueueConnectionFactory();
        try {
            jmsConnectionFactory.setPort(port);
            jmsConnectionFactory.setChannel("channel");
            jmsConnectionFactory.setHostName("host");
            jmsConnectionFactory.setQueueManager("QM");
            jmsConnectionFactory.setTransportType(type);
        }catch (Exception e){}
        return jmsConnectionFactory;
    }

    @Bean
    UserCredentialsConnectionFactoryAdapter adapter(){
        adapter = new UserCredentialsConnectionFactoryAdapter();
        adapter.setTargetConnectionFactory(jmsConnectionFactory);
        adapter.setUsername("username");
        adapter.setPassword("password");

        return adapter;
    }

    @Bean
    JmsComponent wmq()
    {
        JmsComponent wmq=new JmsComponent();
        wmq.setConnectionFactory(adapter);
        return wmq;
    }

and my route looks like

from("wmq:queue:queueName")
                .log(LoggingLevel.INFO, "Message read from WMQ is ${body}")
                .end();

When I run my route, I get the below error

Caused by: org.springframework.beans.factory.BeanCreationException: Error
creating bean with name
'org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration': Injection
of autowired dependencies failed; nested exception is
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,adapter
        at
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at
org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:368)
~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123)
~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1018)
~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)
~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at
org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1192)
~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at
org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1116)
~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at
org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)
~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at
org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:813)
~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at
org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741)
~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        ... 24 common frames omitted
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,adapter
        at
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573)
~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at
org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        ... 45 common frames omitted
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,adapter
        at
org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1126)
~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at
org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)
~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545)
~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        ... 47 common frames omitted


Any advise on how to go about this is highly appreciated. 

Thanks,
Ganga



--
View this message in context: 
http://camel.465427.n5.nabble.com/Accessing-Websphere-MQ-using-credentials-tp5789189.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to