久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

SpringBoot 整合 JMSTemplate的示例代碼

瀏覽:67日期:2023-05-03 18:35:38

1.1 添加依賴

  可以手動在 SpringBoot 項目添加依賴,也可以在項目創建時選擇使用 ActiveMQ 5 自動添加依賴。高版本 SpringBoot (2.0 以上) 在添加 activemq 連接池依賴啟動時會報 Error creating bean with name ’xxx’: Unsatisfied dependency expressed through field ’jmsTemplate’; 可以將 activemq 連接池換成 jms 連接池解決。

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-activemq</artifactId></dependency><!-- activemq 連接池 --><dependency> <groupId>org.apache.activemq</groupId> <artifactId>activemq-pool</artifactId></dependency><!-- jms 連接池 --><dependency> <groupId>org.messaginghub</groupId> <artifactId>pooled-jms</artifactId></dependency>

SpringBoot 整合 JMSTemplate的示例代碼

1.2 添加配置

spring: activemq: broker-url: tcp://127.0.0.1:61616 # 是否是內存模式 in-memory: false pool: # 是否用 PooledConnectionFactory 代替普通的 ConnectionFactory enabled: true # 最大連接數 max-connections: 10 # 連接空閑超時 idle-timeout: 30000

1.3 測試類

/** * Created with IntelliJ IDEA. * * @author Demo_Null * @date 2020/8/5 * @description MQ 測試 */@RunWith(SpringJUnit4ClassRunner.class)@SpringBootTest()public class MyMQTest { @Autowired private JmsTemplate jmsTemplate; @Test public void jms() { jmsTemplate.convertAndSend(new ActiveMQQueue('myTest'), '測試消息'); }}

1.4 運行結果

SpringBoot 整合 JMSTemplate的示例代碼

SpringBoot 整合 JMSTemplate的示例代碼

SpringBoot 整合 JMSTemplate的示例代碼

到此這篇關于SpringBoot 整合 JMSTemplate的示例代碼的文章就介紹到這了,更多相關SpringBoot 整合 JMSTemplate內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Spring
相關文章:
主站蜘蛛池模板: 甘南县| 承德市| 广东省| 静海县| 阿尔山市| 若羌县| 宾阳县| 庆云县| 白城市| 延庆县| 青浦区| 贡山| 商城县| 定远县| 镇巴县| 嘉义市| 浦东新区| 即墨市| 辰溪县| 双江| 宣武区| 灌阳县| 乐平市| 昔阳县| 中宁县| 莲花县| 赤峰市| 莱芜市| 建阳市| 虞城县| 二手房| 澎湖县| 磐安县| 太谷县| 兰溪市| 招远市| 临猗县| 鄢陵县| 永嘉县| 绿春县| 绩溪县|