gpc / jms

JMS integration for Grails.
http://grails.org/plugin/jms
16 stars 28 forks source link

ActiveMQ Example fails due to wrong bean name #21

Closed rlovtangen closed 3 years ago

rlovtangen commented 8 years ago

When using the example config in chapter 2:

spring:
    activemq:
        brokerUrl: vm://localhost
        pooled: true

my application fails on startup with "NoSuchBeanDefinitionException: No bean named 'jmsConnectionFactory' is defined" This is because the bean is called pooledJmsConnectionFactory, not jmsConnectionFactory when pooled is true. Looks like this is due to bean definitions in ActiveMQConnectionFactoryConfiguration:

    @Bean
    @ConditionalOnProperty(prefix = "spring.activemq", name = "pooled", havingValue = "false", matchIfMissing = true)
    public ActiveMQConnectionFactory jmsConnectionFactory(ActiveMQProperties properties) {

    ...

    @Bean(destroyMethod = "stop")
    @ConditionalOnProperty(prefix = "spring.activemq", name = "pooled", havingValue = "true", matchIfMissing = false)
    public PooledConnectionFactory pooledJmsConnectionFactory(

One option is of course to set pooled to false. If setting pooled to true, I can change the expected name by adding the following to application.yml:

jms:
    templates:
        standard:
            connectionFactoryBean: pooledJmsConnectionFactory

Application is then able to start.

But if I add a service which listens to a topic:

class FooService {

    static exposes = ["jms"]

    @Subscriber(topic = "My.topic")
    def bar(msg) {
        println msg
    }
}

I get a NoSuchBeanDefinitionException again because this service obviously also expects a bean named jmsConnectionFactory. Maybe I can fix this by defining container and adapter as pr chapter 5. But another work-around I found is to add a bean alias to resources.groovy:

beans = {
    springConfig.addAlias 'jmsConnectionFactory', 'pooledJmsConnectionFactory'
}

I'm then able to receive messages from topic. Is there a better way? Should the documentation include some more information on this?

jaGarcia commented 6 years ago

Ran into the same problem

github-actions[bot] commented 3 years ago

Stale issue message