前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >解决:A component required a bean of type ‘javax.jms.Queue‘ that could not be found.

解决:A component required a bean of type ‘javax.jms.Queue‘ that could not be found.

作者头像
微风-- 轻许--
发布2022-04-13 15:47:34
1.3K0
发布2022-04-13 15:47:34
举报
文章被收录于专栏:java 微风

1. 情景描述:只是想简单写个 ActiveMQ 的小样,启动服务却报错:

代码语言:javascript
复制
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2018-08-01 16:10:39.858 ERROR 4928 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

A component required a bean of type 'javax.jms.Queue' that could not be found.


Action:

Consider defining a bean of type 'javax.jms.Queue' in your configuration.

2. 原因和解决:

如提示信息中说的一样,Queue 类没有纳入spring 的管理。加上注解: @Bean 就行了。

错误写法:

代码语言:javascript
复制
/**
 * @author silence
 * @date 2018/8/1 10:42
 */
@Component
public class MessageQueue{

    public Queue queue(){
        return new ActiveMQQueue("my-message");
    }

}

正确写法:

代码语言:javascript
复制
package gentle.activemq;

import org.apache.activemq.command.ActiveMQQueue;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import javax.jms.Queue;

/**
 * @author silence
 * @date 2018/8/1 10:42
 */
@Component
public class MessageQueue{
    
    @Bean //返回一个名为 my-message 的队列,并且注册为 bean
    public Queue queue(){
        return new ActiveMQQueue("my-message");
    }

}

3. 成功启动服务:

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2018/08/01 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档