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 org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hornetq.jms.client.HornetQConnectionFactory;
import org.hornetq.jms.server.embedded.EmbeddedJMS;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -37,19 +34,10 @@ import org.springframework.context.annotation.Configuration;
@ConditionalOnMissingBean(ConnectionFactory.class)
class HornetQConnectionFactoryConfiguration {
private static Log logger = LogFactory
.getLog(HornetQEmbeddedServerConfiguration.class);
// Ensure JMS is setup before XA
@Autowired(required = false)
private EmbeddedJMS embeddedJMS;
@Bean
public ConnectionFactory jmsConnectionFactory(HornetQProperties properties) {
if (this.embeddedJMS != null && logger.isDebugEnabled()) {
logger.debug("Using embdedded HornetQ broker");
}
return new HornetQConnectionFactoryFactory(properties)
public ConnectionFactory jmsConnectionFactory(ListableBeanFactory beanFactory,
HornetQProperties properties) {
return new HornetQConnectionFactoryFactory(beanFactory, properties)
.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.TransportConstants;
import org.hornetq.jms.client.HornetQConnectionFactory;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
@ -44,14 +45,20 @@ class HornetQConnectionFactoryFactory {
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");
this.beanFactory = beanFactory;
this.properties = properties;
}
public <T extends HornetQConnectionFactory> T createConnectionFactory(
Class<T> factoryClass) {
try {
startEmbededJms();
return doCreateConnectionFactory(factoryClass);
}
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(
Class<T> factoryClass) throws Exception {
HornetQMode mode = this.properties.getMode();

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

Loading…
Cancel
Save