服务器之家

服务器之家 > 正文

解决springboot+activemq启动报注解错误的问题

时间:2021-10-21 11:00     来源/作者:取静舍浮

springboot+activemq启动报注解错误

Description:
Field jmsMessagingTemplate in com.haozz.demo.mq.PromoteActProducer required a bean of type 'org.springframework.jms.core.JmsMessagingTemplate' that could not be found.

The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)

The following candidates were found but could not be injected:
- Bean method 'jmsMessagingTemplate' in 'JmsAutoConfiguration.MessagingTemplateConfiguration' not loaded because Ancestor org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration did not match

Action:
Consider revisiting the entries above or defining a bean of type 'org.springframework.jms.core.JmsMessagingTemplate' in your configuration.

原因总结有以下3点原因:

1.spring.activemq.pool.enabled=true,线程池开启,后面有空格,且没有引入线程池包

?
1
2
3
4
<dependency>
     <groupId>org.apache.activemq</groupId>
     <artifactId>activemq-pool</artifactId>
 </dependency>

2.springboot版本问题不支持,建议用2.0版本启动

?
1
2
3
4
5
6
<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.1.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>

猜想:估计是因为2.1.0+版本有自己的线程池管理,导致冲突

3.spring.activemq.pool.enabled=false,关闭线程池

springboot整合activemq踩过坑

解决springboot+activemq启动报注解错误的问题

启动时候就关闭了

配置如下

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
server:
 port: 8762
#    context-path: /memeber
eureka:
 client:
   service-url:
     defaultZone: http://localhost:8761/eureka/
spring:
   application:
       name: member
   redis:
       host: 127.0.0.1
       password: 123456
       port: 6379
       pool:
           max-idle: 100
           min-idle: 1
           max-active: 1000
           max-wait: -1
   datasource:
       name: test1
       url: jdbc:mysql://127.0.0.1:3306/dandan-member
       username: root
       password: 123456
       type: com.alibaba.druid.pool.DruidDataSource
       driver-class-name: com.mysql.jdbc.Driver
       filters: stat
       maxActive: 20
       initialSize: 1
       maxWait: 60000
       minIdle: 1
       timeBetweenEvictionRunsMillis: 60000
       minEvictableIdleTimeMillis: 300000
       validationQuery: select 'x'
       testWhileIdle: true
       testOnBorrow: false
       testOnReturn: false
       poolPreparedStatements: true
       maxOpenPreparedStatements: 20
    ##activemq连接信息
activemq:
   broker-url: tcp://localhost:61616
   in-memory: true
   pool:
     enabled: false
##队列
messages:
    queue: messages_queue

解决如下

原本activemq 没有在spring.后面直接在前面了,与spring同级了

解决后配置如下

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
server:
 port: 8762
#    context-path: /memeber
eureka:
 client:
   service-url:
     defaultZone: http://localhost:8761/eureka/
spring:
   application:
       name: member
   redis:
       host: 127.0.0.1
       password: 123456
       port: 6379
       pool:
           max-idle: 100
           min-idle: 1
           max-active: 1000
           max-wait: -1
   datasource:
       name: test1
       url: jdbc:mysql://127.0.0.1:3306/dandan-member
       username: root
       password: 123456
       type: com.alibaba.druid.pool.DruidDataSource
       driver-class-name: com.mysql.jdbc.Driver
       filters: stat
       maxActive: 20
       initialSize: 1
       maxWait: 60000
       minIdle: 1
       timeBetweenEvictionRunsMillis: 60000
       minEvictableIdleTimeMillis: 300000
       validationQuery: select 'x'
       testWhileIdle: true
       testOnBorrow: false
       testOnReturn: false
       poolPreparedStatements: true
       maxOpenPreparedStatements: 20
    ##activemq连接信息
   activemq:
       broker-url: tcp://localhost:61616
       in-memory: true
       pool:
          enabled: false
##队列
messages:
    queue: messages_queue

建议。yml缩进要四个字节。一个字节不容易分辨

以上为个人经验,希望能给大家一个参考,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/a544019293/article/details/88179954

相关文章

热门资讯

yue是什么意思 网络流行语yue了是什么梗
yue是什么意思 网络流行语yue了是什么梗 2020-10-11
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全 2019-12-26
背刺什么意思 网络词语背刺是什么梗
背刺什么意思 网络词语背刺是什么梗 2020-05-22
2021年耽改剧名单 2021要播出的59部耽改剧列表
2021年耽改剧名单 2021要播出的59部耽改剧列表 2021-03-05
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总 2020-11-13
返回顶部