ActiveMQ中数据默认存储在kahaDB中,这里将它改为存储在MySQL中
1.将spring-jdbc-4.3.26.RELEASE.jar放入lib目录下
2.修改activemq.xml文件
PropertyPlaceholderConfigurer中添加db.properties
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>file:${activemq.conf}/credentials.properties</value>
<value>file:${activemq.conf}/db.properties</value>
</list>
</property>
</bean>
修改persistenceAdapter为:
<persistenceAdapter>
<jdbcPersistenceAdapter dataSource="#mySqlDataSource_data"/>
</persistenceAdapter>
添加id为mySqlDataSource_data的bean
<bean id="mySqlDataSource_data" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url_data}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
新建文件db.properties,内容为:
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url_data=jdbc:mysql://127.0.0.1:3306/activemq_data?autoReconnect=true&useUnicode=true&characterEncoding=utf8
jdbc.username=root
jdbc.password=a123
重启服务后可以在数据库中发现生成的表