activeMQ-all "5.15.3"不适用于 Spring 5



我正在将弹簧从4.x.x更新为弹簧5.0.3。该项目使用ActiveMQ版本5.15.3。当我尝试使用春季最新版本的应用程序部署应用程序时,我会收到此错误:

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

我注意到ActiveMQ具有春季版本" 4.3.9"作为依赖性。此版本没有" AbsTracThandLermapping"中的" getapplicationContext",因此问题。有没有办法将春季库从ActiveMQ-ALL捆绑包中排除?

我认为这也是我的问题,但是我最终将我的春季WebApp部署在Tomee上,以成功地连接并使用ActiveMQ托管并在内部与该Tomcat容器内部运行。

我正在使用Spring 5.0.3释放和ActiveMQ-CLIENT 5.15.3。我不需要毛从阴影的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<String>(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<Widget> dequeue() {
    Optional<Widget> 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;
  }
}

感谢上面的Matthew K。我也发现了。Activemq-All在其中包装了Spring(当前是4.x版本(的版本。与弹簧v.5之间有一些不可兼容的更改。我自己遇到了其他春季课程之一。它可能导致这种问题(在我的情况下没有这种方法例外(。我遇到了ActiveMQ 5.15.4和Spring 5.0.7的问题。最后,我使用更细的胶水罐解决了它。我必须使用所有这些:ActiveMQ-Broker,ActiveMQ-CLIENT,ACTIVEMQ-POOL,ACTIVEMQ-KAHADB商店,ActiveMQ-Spring

最新更新