Koi*_*rab 0 java jms spring-boot
从 SpringBoot v.2.5.5 更新到 v3.1.0 后,还需要ConnectionFactory从更新javax.jms.ConnectionFactory到jakarta.jms.ConnectionFactory。我没有改变任何其他东西。不幸的是现在我收到这样的错误:
ERROR - Could not refresh JMS Connection for destination 'tServerEvent' - retrying using FixedBackOff{interval=5000, currentAttempts=0, maxAttempts=unlimited}. Cause: Could not connect to broker URL: tcp://localhost:61616. Reason: java.net.ConnectException: Connection refused: no further information
我调查了它并与旧的进行了比较javax.ConnectionFactory,似乎brokerUrl它们的默认值是不同的
因为javax.jms.ConnectionFactory它是:vm://localhost?broker.persistent=false
因为jakarta.jms.ConnectionFactory它是:tcp://localhost:61616
即使我手动设置经纪人网址,如下所示:
spring:
activemq:
broker-url: vm://localhost?broker.persistent=false
Run Code Online (Sandbox Code Playgroud)
它仍然无法工作,错误是: Cause: Could not create Transport. Reason: java.io.IOException: Transport scheme NOT recognized: [vm]
我不知道为什么 jakarta.ConnectionFactory 和旧 javax.ConnectionFactory 的默认brokerUrl 不同,也不知道如何成功运行我的应用程序。如果您能给我一些提示,我将不胜感激。
下面是带有JmsListenerContainerFacrotyConnectionFactory 的 Bean 的代码:
import jakarta.jms.ConnectionFactory;
import org.springframework.boot.autoconfigure.jms.DefaultJmsListenerContainerFactoryConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jms.annotation.EnableJms;
import org.springframework.jms.config.DefaultJmsListenerContainerFactory;
import org.springframework.jms.config.JmsListenerContainerFactory;
@Configuration
@EnableJms
public class JmsConfig {
@Bean
public JmsListenerContainerFactory<?> myFactory(ConnectionFactory connectionFactory, DefaultJmsListenerContainerFactoryConfigurer configurer) {
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
configurer.configure(factory, connectionFactory);
return factory;
}
}
Run Code Online (Sandbox Code Playgroud)
Spring Boot 3.0 中删除了对 ActiveMQ 的支持,因为它不支持 JMS 3.0(jakarta.jms.*API)。Spring Boot 3.1恢复了对自动配置 ActiveMQ 客户端的支持。由于 ActiveMQ 的代理尚不支持 JMS 3.0,因此嵌入式代理支持尚未恢复。
要在 Spring Boot 3.1 中使用 ActiveMQ,您必须像Spring Boot 的 ActiveMQ 冒烟测试那样使用外部代理。
| 归档时间: |
|
| 查看次数: |
5628 次 |
| 最近记录: |