经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » Java相关 » Spring » 查看文章
解决springboot+activemq启动报注解错误的问题
来源:jb51  时间:2021/7/26 12:06:54  对本文有异议

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. <dependency>
  2. <groupId>org.apache.activemq</groupId>
  3. <artifactId>activemq-pool</artifactId>
  4. </dependency>

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

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

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

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

springboot整合activemq踩过坑

启动时候就关闭了

配置如下

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

解决如下

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

解决后配置如下

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

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

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

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号