У меня есть следующие зависимости:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-activemq</artifactId>
<version>1.5.10.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jms</artifactId>
<version>5.0.3.RELEASE</version>
</dependency>
и следующий исходный код:
@SpringBootApplication
@EnableJms
public class ArApplication {
@Autowired
private JmsTemplate jmsTemplate;
private static final Logger logger = LoggerFactory.getLogger(ArApplication.class);
public static void main(String[] args) throws InterruptedException {
ConfigurableApplicationContext context = SpringApplication.run(Application.class, args);
JmsTemplate jmsTemplate = context.getBean(JmsTemplate.class);
jmsTemplate.convertAndSend("robotCommand", "test");
}
public ConnectionFactory jmsConnectionFactory() {
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");
return connectionFactory;
}
}
И мое приложение не могло запуститься:
Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.jms.core.JmsTemplate' available
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:353)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:340)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1092)
at pack.ArApplication.main(ArApplication.java:34)
В чем причина?
@EnableJms
автоматически раскрывает JmsTemplate. На самом деле вам нужно определить компонент в первую очередь. У вас есть другие конфигурации или это все? - person Setu   schedule 01.02.2018ArApplication
, а контекст, который вы получаете, используетApplication
. это опечатка или у вас разные классы приложений? - person Setu   schedule 01.02.2018