java ActiveMQ配置和Spring表达式语言(SpEL)
我必须在同一台具有持久嵌入式代理的机器上启动这一服务的多个实例(单独的JVM)。所有配置文件都是预先生成的,并在服务启动之前以编译方式进行变量替换。我遇到了几个试图获得AMQ数据目录和KahaDB锁的实例的问题,很明显,第一个实例成功地获得了锁,其余的继续尝试失败
我需要设置如下内容:
. . .
<amq:broker dataDirectory="${activemq.directory}/data" id="broker" persistent="true" useJmx="false" >
. . .
我尝试了PropertyPlaceHolderConfigure,但据我所知,它从Spring配置中指定的文件加载属性,启动时已经太晚了。我试图使用Spring表达式语言,所以我最终得到了这样的结果:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jms="http://www.springframework.org/schema/jms"
xmlns:amq="http://activemq.apache.org/schema/core"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/jms
http://www.springframework.org/schema/jms/spring-jms-3.0.xsd
http://activemq.apache.org/schema/core
http://activemq.apache.org/schema/core/activemq-core-5.5.0.xsd">
<!-- Embedded ActiveMQ Broker -->
<amq:broker dataDirectory="#{systemProperties['activemq.directory']}/data" id="broker" persistent="true" useJmx="false" >
...
我在命令行上传递
-Dactivemq.directory=<my-directory>
在日志上我看到了
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named '{systemProperties['activemq.directory']}/data' is defined
我是不是错过了AMQ和Spring3 SpEL的一些东西?有没有其他的解决办法?同样的人认为我可能错过了吗
# 1 楼答案
最后,我只是简单地使用了旧的PropertyPlaceHolderConfigure,删除了SpEL符号,它就像一个符咒