我开发了一个Spring启动应用程序,它使用JMS在Activemq中发送和监听消息,但在运行应用程序时,JMS无法在Spring启动时启动
这里是主舱Application.java
@SpringBootApplication
@EnableJms
public class Main {
public static void main(String[] args) {
SpringApplication.run(Main.class, args);
}
}
配置类:Config.java
@Configuration
public class Config {
@Bean
public Queue queue() {
return new ActiveMQQueue("inmemory.queue");
}
@Bean
public JmsTemplate jmsTemplate() {
return new JmsTemplate(activeMQConnectionFactory());
}
}
侦听器类用于侦听队列:Listener.java
@Component
public class Listener {
@JmsListener(destination = "inmemory.queue")
public void listener(String message) {
System.out.println("message received" + message);
}
}
Producer类用于从控制器Producer.java向队列发送消息
@RestController
public class Producer {
@Autowired
Queue queue;
@Autowired
JmsTemplate jmstemplate;
@RequestMapping(method = RequestMethod.GET, path = "/test3/{message}")
public String test3(@PathVariable String message) {
jmstemplate.convertAndSend(queue, message);
return "teste3" + message;
}
}
application.properties
spring.activemq.in-memory=true
spring.activemq.pool.enabled=false
server.port=8081
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-activemq</artifactId>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-broker</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jms</artifactId>
<version>5.1.4.RELEASE</version>
</dependency>
</dependencies>
</project>
这是在不启动JMS的情况下启动应用程序的屏幕截图
请使用以下代码作为jmsTemplate(…)方法。
@Bean
public JmsTemplate jmsTemplate() {
return new JmsTemplate(new ActiveMQConnectionFactory("vm://localhost"));
}
我已经测试过了,它正在工作,如果您需要示例代码,请告诉我。
此外,当您使用启动器时,无需在本地安装ActiveMQ。
输出
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.6.RELEASE)
2019-09-16 12:39:15.477 INFO 14111 --- [ main] c.e.activeissue.ActiveIssueApplication : Starting ActiveIssueApplication on kode12-B250M-D3H with PID 14111 (/home/yprajapati/Downloads/active-issue/target/classes started by yprajapati in /home/yprajapati/Downloads/active-issue)
2019-09-16 12:39:15.493 INFO 14111 --- [ main] c.e.activeissue.ActiveIssueApplication : No active profile set, falling back to default profiles: default
2019-09-16 12:39:16.895 INFO 14111 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8081 (http)
2019-09-16 12:39:16.919 INFO 14111 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-09-16 12:39:16.919 INFO 14111 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.21]
2019-09-16 12:39:16.991 INFO 14111 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-09-16 12:39:16.991 INFO 14111 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1407 ms
2019-09-16 12:39:17.204 INFO 14111 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-09-16 12:39:17.440 INFO 14111 --- [ main] o.apache.activemq.broker.BrokerService : Using Persistence Adapter: MemoryPersistenceAdapter
2019-09-16 12:39:17.505 INFO 14111 --- [ JMX connector] o.a.a.broker.jmx.ManagementContext : JMX consoles can connect to service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi
2019-09-16 12:39:17.574 INFO 14111 --- [ main] o.apache.activemq.broker.BrokerService : Apache ActiveMQ 5.15.9 (localhost, ID:kode12-B250M-D3H-39191-1568617757456-0:1) is starting
2019-09-16 12:39:17.577 INFO 14111 --- [ main] o.apache.activemq.broker.BrokerService : Apache ActiveMQ 5.15.9 (localhost, ID:kode12-B250M-D3H-39191-1568617757456-0:1) started
2019-09-16 12:39:17.577 INFO 14111 --- [ main] o.apache.activemq.broker.BrokerService : For help or more information please see: http://activemq.apache.org
2019-09-16 12:39:17.594 INFO 14111 --- [ main] o.a.activemq.broker.TransportConnector : Connector vm://localhost started
2019-09-16 12:39:17.734 INFO 14111 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8081 (http) with context path ''
2019-09-16 12:39:17.737 INFO 14111 --- [ main] c.e.activeissue.ActiveIssueApplication : Started ActiveIssueApplication in 2.872 seconds (JVM running for 3.326)
它永远不会结束,应用程序也不会响应: 我已经检查了以下几点: 我的应用程序扩展了SpringBootServletInitializer 我将初学者tomcat依赖项放在提供的中 war名为“EdgeCustomerOfferStorageWeb.war”,实例端口为10080,因此我使用:http://server:10080/EdgeCustomerOfferStorageWeb/It不响应,
我在stackoverflow上发现了类似的问题,并试图用这种方式(LINK)解决这个问题,但在我的项目中没有起作用。谁能给我一些建议吗? pom.xml 应用属性
使用spring-boot时,一切工作都很好。尽管如此,在spring-boot中已删除了注释和。我试图将代码重构为新版本,但我做不到。对于以下测试,我的应用程序在测试之前没有启动,http://localhost:8080返回404: 如何重构测试以使其在Spring-Boot1.5中工作?
我想启用或禁用具有外部配置的SSL/TLS,这些配置可以在应用程序启动期间提供。应用程序应该支持http和HTTPS的所有crud操作。 既然上面的属性是不推荐使用的,那么我如何在不使用配置文件的情况下实现它。
我试图在SpringMVC中运行SpringBoot应用程序,在SpringMVCPOM中添加SpringBoot应用程序依赖项,并扫描SpringBoot包,但我面临以下问题
我构建了一个侦听JMS.queue的简单MDB应用程序,并将其部署在IBM WARS 8.5.5上(使用IBM MQ作为JMS代理),当尝试启动它时,我收到以下错误(对不起,西里尔符号,尝试仔细翻译): 我的消息驱动ejb-mdb模块MDBListener.java: ejb-mdb模块ejb-jar.xml: ejb-mdb模块ibm-ejb-jar-bnd.xml: