Spring boot JMS未在Spring引导应用程序中启动

Spring boot JMS未在Spring引导应用程序中启动,spring-boot,jms,activemq,Spring Boot,Jms,Activemq,我开发了一个SpringBoot应用程序,它使用JMS在Activemq中发送和侦听消息,但在运行应用程序时,JMS并没有通过SpringBoot启动 这是mainclass,Application.java @SpringBootApplication @EnableJms public class Main { public static void main(String[] args) { SpringApplication.run(Main.class, args

我开发了一个SpringBoot应用程序,它使用JMS在Activemq中发送和侦听消息,但在运行应用程序时,JMS并没有通过SpringBoot启动

这是mainclass,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类用于侦听队列: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;
    }
}
应用程序属性

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>

org.springframework.boot

请为
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)

您好,显示了什么错误?您能补充一下您的问题吗?没有错误,我是spring boot新手。我正在使用eclipse。问题是程序正在运行,但JMS未启动。请提供您的pom。xml@YogeshPrajapati添加了pom.xml。。请help@JonathanJohx .. 请查找其显示错误:无法刷新目标“inmemory.queue”的JMS连接-正在使用FixedBackOff重试{interval=5000,currentAttempts=5,maxAttempts=unlimited}。原因:无法创建传输。原因:java.io.IOException:无法识别传输方案:[vm在这种情况下,请在您的问题中提供activeMQConnectionFactory()方法的实现。