Fix HornetQ ClassNotFound issues when not embedded

Update HornetQConnectionFactoryConfiguration and
HornetQXAConnectionFactoryConfiguration so that they no longer depend
on the HornetQ EmbeddedJMS class. EmbeddedJMS beans are started
(when possible) from the HornetQConnectionFactoryFactory.

Fixes gh-1480
pull/1487/head
Phillip Webb 10 years ago
parent c8809afe1b
commit 5774e808c7

@ -18,11 +18,8 @@ package org.springframework.boot.autoconfigure.jms.hornetq;
import javax.jms.ConnectionFactory; import javax.jms.ConnectionFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hornetq.jms.client.HornetQConnectionFactory; import org.hornetq.jms.client.HornetQConnectionFactory;
import org.hornetq.jms.server.embedded.EmbeddedJMS; import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -37,19 +34,10 @@ import org.springframework.context.annotation.Configuration;
@ConditionalOnMissingBean(ConnectionFactory.class) @ConditionalOnMissingBean(ConnectionFactory.class)
class HornetQConnectionFactoryConfiguration { class HornetQConnectionFactoryConfiguration {
private static Log logger = LogFactory
.getLog(HornetQEmbeddedServerConfiguration.class);
// Ensure JMS is setup before XA
@Autowired(required = false)
private EmbeddedJMS embeddedJMS;
@Bean @Bean
public ConnectionFactory jmsConnectionFactory(HornetQProperties properties) { public ConnectionFactory jmsConnectionFactory(ListableBeanFactory beanFactory,
if (this.embeddedJMS != null && logger.isDebugEnabled()) { HornetQProperties properties) {
logger.debug("Using embdedded HornetQ broker"); return new HornetQConnectionFactoryFactory(beanFactory, properties)
}
return new HornetQConnectionFactoryFactory(properties)
.createConnectionFactory(HornetQConnectionFactory.class); .createConnectionFactory(HornetQConnectionFactory.class);
} }

@ -27,6 +27,7 @@ import org.hornetq.core.remoting.impl.invm.InVMConnectorFactory;
import org.hornetq.core.remoting.impl.netty.NettyConnectorFactory; import org.hornetq.core.remoting.impl.netty.NettyConnectorFactory;
import org.hornetq.core.remoting.impl.netty.TransportConstants; import org.hornetq.core.remoting.impl.netty.TransportConstants;
import org.hornetq.jms.client.HornetQConnectionFactory; import org.hornetq.jms.client.HornetQConnectionFactory;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.ClassUtils; import org.springframework.util.ClassUtils;
@ -44,14 +45,20 @@ class HornetQConnectionFactoryFactory {
private final HornetQProperties properties; private final HornetQProperties properties;
public HornetQConnectionFactoryFactory(HornetQProperties properties) { private final ListableBeanFactory beanFactory;
public HornetQConnectionFactoryFactory(ListableBeanFactory beanFactory,
HornetQProperties properties) {
Assert.notNull(beanFactory, "BeanFactory must not be null");
Assert.notNull(properties, "Properties must not be null"); Assert.notNull(properties, "Properties must not be null");
this.beanFactory = beanFactory;
this.properties = properties; this.properties = properties;
} }
public <T extends HornetQConnectionFactory> T createConnectionFactory( public <T extends HornetQConnectionFactory> T createConnectionFactory(
Class<T> factoryClass) { Class<T> factoryClass) {
try { try {
startEmbededJms();
return doCreateConnectionFactory(factoryClass); return doCreateConnectionFactory(factoryClass);
} }
catch (Exception ex) { catch (Exception ex) {
@ -60,6 +67,17 @@ class HornetQConnectionFactoryFactory {
} }
} }
private void startEmbededJms() {
if (ClassUtils.isPresent(EMBEDDED_JMS_CLASS, null)) {
try {
this.beanFactory.getBeansOfType(Class.forName(EMBEDDED_JMS_CLASS));
}
catch (Exception ex) {
// Ignore
}
}
}
private <T extends HornetQConnectionFactory> T doCreateConnectionFactory( private <T extends HornetQConnectionFactory> T doCreateConnectionFactory(
Class<T> factoryClass) throws Exception { Class<T> factoryClass) throws Exception {
HornetQMode mode = this.properties.getMode(); HornetQMode mode = this.properties.getMode();

@ -19,11 +19,8 @@ package org.springframework.boot.autoconfigure.jms.hornetq;
import javax.jms.ConnectionFactory; import javax.jms.ConnectionFactory;
import javax.transaction.TransactionManager; import javax.transaction.TransactionManager;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hornetq.jms.client.HornetQXAConnectionFactory; import org.hornetq.jms.client.HornetQXAConnectionFactory;
import org.hornetq.jms.server.embedded.EmbeddedJMS; import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
@ -43,21 +40,13 @@ import org.springframework.context.annotation.Configuration;
@ConditionalOnBean(XAConnectionFactoryWrapper.class) @ConditionalOnBean(XAConnectionFactoryWrapper.class)
class HornetQXAConnectionFactoryConfiguration { class HornetQXAConnectionFactoryConfiguration {
private static Log logger = LogFactory
.getLog(HornetQEmbeddedServerConfiguration.class);
// Ensure JMS is setup before XA
@Autowired(required = false)
private EmbeddedJMS embeddedJMS;
@Bean @Bean
public ConnectionFactory jmsConnectionFactory(HornetQProperties properties, public ConnectionFactory jmsConnectionFactory(ListableBeanFactory beanFactory,
XAConnectionFactoryWrapper wrapper) throws Exception { HornetQProperties properties, XAConnectionFactoryWrapper wrapper)
if (this.embeddedJMS != null && logger.isDebugEnabled()) { throws Exception {
logger.debug("Using embdedded HornetQ broker with XA");
}
return wrapper.wrapConnectionFactory(new HornetQConnectionFactoryFactory( return wrapper.wrapConnectionFactory(new HornetQConnectionFactoryFactory(
properties).createConnectionFactory(HornetQXAConnectionFactory.class)); beanFactory, properties)
.createConnectionFactory(HornetQXAConnectionFactory.class));
} }
} }

Loading…
Cancel
Save