java mq5.15,activemq-所有“ 5.15.3”不适用于Spring 5

I am updating Spring from 4.x.x to Spring 5.0.3. The project uses ActiveMQ version 5.15.3. When I try to deploy the application with the newest version of Spring I get this error:

Caused by: java.lang.NoSuchMethodError: org.springframework.web.servlet.handler.AbstractHandlerMapping.obtainApplicationContext()Lorg/springframework/context/ApplicationContext;

at org.springframework.web.servlet.handler.AbstractHandlerMapping.detectMappedInterceptors(AbstractHandlerMapping.java:269)

at org.springframework.web.servlet.handler.AbstractHandlerMapping.initApplicationContext(AbstractHandlerMapping.java:243)

at org.springframework.web.servlet.handler.SimpleUrlHandlerMapping.initApplicationContext(SimpleUrlHandlerMapping.java:102)

at org.springframework.context.support.ApplicationObjectSupport.initApplicationContext(ApplicationObjectSupport.java:120)

at org.springframework.web.context.support.WebApplicationObjectSupport.initApplicationContext(WebApplicationObjectSupport.java:77)

at org.springframework.context.support.ApplicationObjectSupport.setApplicationContext(ApplicationObjectSupport.java:74)

at org.springframework.context.support.ApplicationContextAwareProcessor.invokeAwareInterfaces(ApplicationContextAwareProcessor.java:121)

at org.springframework.context.support.ApplicationContextAwareProcessor.postProcessBeforeInitialization(ApplicationContextAwareProcessor.java:97)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:409)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1620)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)

... 53 more

I noticed that ActiveMQ has Spring version "4.3.9" as a dependency. This version does not have the method "obtainApplicationContext" in "AbstractHandlerMapping" and hence the problem. Is there a way exclude the Spring libraries from the activemq-all bundle?

解决方案

I thought this was my problem too but I eventually got my Spring webapp deployed on TomEE to successfully connect and use ActiveMQ hosted and running internally to that Tomcat container.

I'm using Spring 5.0.3-RELEASE and activemq-client 5.15.3. I didn't need everything in the maven shaded uber jar activemq-all.

@Configuration

public class MyConfig {

@Bean

public SingleConnectionFactory connectionFactory() {

ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost");

((ActiveMQConnectionFactory) connectionFactory)

// See http://activemq.apache.org/objectmessage.html why we set trusted packages

.setTrustedPackages(new ArrayList(Arrays.asList("com.mydomain", "java.util")));

return new SingleConnectionFactory(connectionFactory);

}

@Bean

@Scope("prototype")

public JmsTemplate jmsTemplate() {

return new JmsTemplate(connectionFactory());

}

@Bean

public Queue myQueue() throws JMSException {

Connection connection = connectionFactory().createConnection();

connection.start();

Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

Queue queue = session.createQueue("message-updates");

return queue;

}

}

@Component

public class MyQueueImpl implements MyQueue {

@Inject

private JmsTemplate jmsTemplate;

@Inject

private Queue myQueue;

@PostConstruct

public void init() {

jmsTemplate.setReceiveTimeout(JmsTemplate.RECEIVE_TIMEOUT_NO_WAIT);

}

@Override

public void enqueue(Widget widget) {

jmsTemplate.send(myQueue, new MessageCreator() {

@Override

public Message createMessage(Session session) throws JMSException {

return session.createObjectMessage(widget);

}

});

}

@Override

public Optional dequeue() {

Optional widget = Optional.empty();

ObjectMessage message = (ObjectMessage) jmsTemplate.receive(myQueue);

try {

if (message != null) {

widget = Optional.ofNullable((Widget) message.getObject());

message.acknowledge();

}

} catch (JMSException e) {

throw new UncategorizedJmsException(e);

}

return widget;

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值