gpc / jms

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

Add support for Grails 4 #41

Closed tylervz closed 4 years ago

tylervz commented 4 years ago

We cannot upgrade to Grails 4.0.1 because this plugin is throwing an exception.

Right now the dependencies section in our build.gradle has the following:

compile 'org.grails.plugins:jms:2.0.0.RC2'
    compile 'org.springframework:spring-jms:5.1.5.RELEASE'
    compile 'javax.jms:javax.jms-api:2.0.1'
    runtime 'org.apache.activemq:activemq-spring:5.15.8'

And we get this error when trying to run the application:

A component required a bean named 'jmsConnectionFactory' that could not be found.

The following candidates were found but could not be injected:
    - Bean method 'jmsConnectionFactory' in 'ActiveMQXAConnectionFactoryConfiguration' not loaded because @ConditionalOnBean (types: org.springframework.boot.jms.XAConnectionFactoryWrapper; SearchStrategy: all) did not find any beans of type org.springframework.boot.jms.XAConnectionFactoryWrapper

Action:

Consider revisiting the entries above or defining a bean named 'jmsConnectionFactory' in your configuration.

I created a repo that demonstrates this. Use the jms branch. https://github.com/tylervz/grails4jms/tree/jms

aulea commented 4 years ago

Did pull-request to your sample project with different configuration setup.

But main issue with newer Spring's is that it uses for different configuration setup different bean names for JmsConnectionFactory, there is not always only 'jmsConnectionFactory'.

With SpringBoot default configuration the bean name is actually 'cachingJmsConnectionFactory' To turn caching off use configuration spring.jms.cache.enabled=false, then there will be bean with name 'jmsConnectionFactory'. When you use pooling spring.activemq.pool.enabled=true, then there will be bean with name 'pooledJmsConnectionFactory'.

To overcome those different namings, then you can use spring bean alias'es in resources.groovy. springConfig.addAlias('jmsConnectionFactory', 'pooledJmsConnectionFactory') or springConfig.addAlias('jmsConnectionFactory', 'cachingJmsConnectionFactory')

OR you override jms plugin default configuration and use not jmsConnectionFactory naming: https://github.com/gpc/jms/blob/2.0.x/src/main/groovy/grails/plugin/jms/bean/DefaultJmsBeans.groovy

tylervz commented 4 years ago

Thanks! I got it working now.