Java activemq all";5.15.3“;不适用于弹簧5
我正在将Spring从4.x.x更新到Spring 5.0.3。该项目使用ActiveMQ版本5.15.3。当我尝试使用最新版本的Spring部署应用程序时,出现以下错误:Java activemq all";5.15.3“;不适用于弹簧5,java,spring,activemq,Java,Spring,Activemq,我正在将Spring从4.x.x更新到Spring 5.0.3。该项目使用ActiveMQ版本5.15.3。当我尝试使用最新版本的Spring部署应用程序时,出现以下错误: Caused by: java.lang.NoSuchMethodError: org.springframework.web.servlet.handler.AbstractHandlerMapping.obtainApplicationContext()Lorg/springframework/context/Appli
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”中的“AcquitainApplicationContext”方法,因此存在问题。是否有办法将Spring库从activemq all捆绑包中排除?我认为这也是我的问题,但我最终在TomEE上部署了我的Spring webapp,以成功连接并使用托管并在内部运行的activemq到Tomcat容器 我正在使用Spring5.0.3-RELEASE和activemq客户端5.15.3。我并不需要maven shaded uber jar中的所有东西
@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;
}
}
@配置
公共类MyConfig{
@豆子
公共SingleConnectionFactory connectionFactory(){
ConnectionFactory ConnectionFactory=new-ActiveMQConnectionFactory(“vm://localhost”);
((ActiveMQConnectionFactory)connectionFactory)
//看http://activemq.apache.org/objectmessage.html 为什么要设置受信任的包
.setTrustedPackages(新的ArrayList(Arrays.asList(“com.mydomain”、“java.util”));
返回新的SingleConnectionFactory(connectionFactory);
}
@豆子
@范围(“原型”)
公共JmsTemplate JmsTemplate(){
返回新的JmsTemplate(connectionFactory());
}
@豆子
公共队列myQueue()引发JMSException{
连接=connectionFactory().createConnection();
connection.start();
会话会话=connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
Queue Queue=session.createQueue(“消息更新”);
返回队列;
}
}
@组成部分
公共类MyQueueImpl实现MyQueue{
@注入
私有JmsTemplate JmsTemplate;
@注入
私有队列;
@施工后
公共void init(){
setReceiveTimeout(jmsTemplate.RECEIVE_TIMEOUT_NO_WAIT);
}
@凌驾
公共无效排队(小部件){
发送(myQueue,newmessagecreator()){
@凌驾
公共消息createMessage(会话)引发JMSExException{
返回session.createObjectMessage(小部件);
}
});
}
@凌驾
公共可选出列(){
可选小部件=Optional.empty();
ObjectMessage消息=(ObjectMessage)jmsTemplate.receive(myQueue);
试一试{
如果(消息!=null){
widget=Optional.ofNullable((widget)message.getObject());
message.acknowledge();
}
}捕获(JME){
抛出新的未分类jmscexception(e);
}
返回控件;
}
}
谢谢上面的Matthew K。我也发现了。ActiveMQ都在其中打包了一个版本的spring(目前是4.x版本)。这与spring v.5之间存在一些不向后兼容的更改。我自己在另一个spring类中遇到了一个新方法。它可能会导致这种问题(在我的例子中没有这种方法异常)。
我在activeMQ 5.15.4和spring 5.0.7中遇到了这个问题。最后,我用更细粒度的罐子解决了这个问题。我必须使用所有这些:activemq代理、activemq客户端、activemq池、activemq存储、activemq spring您使用哪个构建系统?专家Gradle?我在用Ant+Ivy