簡體   English   中英

activemq-all“ 5.15.3”不適用於Spring 5

[英]activemq-all “5.15.3” does not work with Spring 5

我將Spring從4.xx更新到Spring 5.0.3。 該項目使用ActiveMQ版本5.15.3。 當我嘗試使用最新版本的Spring部署應用程序時,出現以下錯誤:

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具有Spring版本“ 4.3.9”作為依賴項。 此版本在“ AbstractHandlerMapping”中沒有方法“ obtainApplicationContext”,因此存在問題。 有沒有辦法從activemq-all捆綁包中排除Spring庫?

我以為這也是我的問題,但最終我將Spring webapp部署在TomEE上,以成功連接並使用ActiveMQ托管並在該Tomcat容器內部運行。

我正在使用Spring 5.0.3-RELEASE和activemq-client 5.15.3。 我不需要Maven着色的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;
  }
}

感謝上面的MatthewK。 我也發現了。 ActiveMQ-all內部都包裝了spring的一個版本(當前是4.x版本)。 與Spring v.5之間有一些向后兼容的更改。 我本人在其他春季班中遇到了一種新方法。 可能導致這種問題(我的情況下沒有這種方法異常)。 我在activeMQ 5.15.4和Spring 5.0.7中遇到了這個問題。 最后,我改用細顆粒的罐子解決了。 我必須使用所有這些:activemq-broker,activemq-client,activemq-pool,activemq-kahadb-store,activemq-spring

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM