补充@Petter和@April的答案,下面是相同的解决方案,但有更完整的示例:
1. Petter解决方案,在连接工厂url导入activemq.xml
构建.gradle
ext {
springBootVersion = "1.5.3.RELEASE"
activeMQVersion = "5.14.5"
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-activemq:${springBootVersion}")
compile("org.apache.activemq:activemq-broker:${activeMQVersion}")
testCompile("org.springframework.boot:spring-boot-starter-test:${springBootVersion}")
testCompile group: 'org.apache.activemq', name: 'activemq-spring', version: "${activeMQVersion}"
testCompile("junit:junit:4.12")
}
src/main/resources/activemq.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:amq="http://activemq.apache.org/schema/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://activemq.apache.org/schema/core
http://activemq.apache.org/schema/core/activemq-core-5.4.0.xsd
">
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="broker1" persistent="false" >
<transportConnectors>
<transportConnector name="vm" uri="vm://broker1"/>
</transportConnectors>
</broker>
</beans>
配置文件
@EnableJms
@SpringBootApplication
@EnableAutoConfiguration
@Configuration
public class Config {}
应用程序属性
spring.activemq.broker-url=vm://broker1?brokerConfig=xbean:activemq.xml
2.4月份的解决方案,在Spring Configuration处导入activemq.xml
只需删除application.properties
然后加@ImportResource("classpath:activemq.xml")
进入配置文件
配置文件
@EnableJms
@SpringBootApplication
@EnableAutoConfiguration
@Configuration
@ImportResource("classpath:activemq.xml")
public class Config {}