Нет подходящего компонента типа «org.springframework.jms.core.JmsTemplate»

У меня есть следующие зависимости:

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

В чем причина?


person gstackoverflow    schedule 01.02.2018    source источник
comment
Я не думаю, что простое добавление @EnableJms автоматически раскрывает JmsTemplate. На самом деле вам нужно определить компонент в первую очередь. У вас есть другие конфигурации или это все?   -  person Setu    schedule 01.02.2018
comment
@Setu, я не вижу здесь никаких дополнительных конфигураций spring.io/guides/gs/messaging -jms   -  person gstackoverflow    schedule 01.02.2018
comment
Извиняюсь, исправил и спасибо за ссылку. Только что заметил в коде, что имя вашего класса ArApplication, а контекст, который вы получаете, использует Application. это опечатка или у вас разные классы приложений?   -  person Setu    schedule 01.02.2018
comment
@Setu, это основная причина, спасибо   -  person gstackoverflow    schedule 01.02.2018
comment
@Setu на самом деле я вижу следующую ошибку: > stackoverflow.com/questions/48567562/   -  person gstackoverflow    schedule 01.02.2018
comment
@gstackoverflow, тогда вы можете удалить свой вопрос? Здесь он помечен как оставшийся без ответа, поэтому люди зря тратят время на ваш вопрос.   -  person Stephane Nicoll    schedule 26.02.2018


Ответы (1)


Я добавил в свой тестовый класс:

@AutoConfigureMockMvc()
@ContextConfiguration(classes = MusicPlayerApplication.class)  

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, классы = Server.class)

class DecoratorQueueServiceTest {
}
person Дмитрий Дорошук    schedule 15.07.2021