我必须在具有持久嵌入式代理的同一台计算机上启动此服务的多个实例(单独的 JVM)。所有配置文件都是预先生成的,并在服务启动之前以编译方式完成变量替换。我在尝试获取 AMQ 数据目录和 KahaDB 锁的多个实例时遇到问题,显然第一个实例成功获取了锁,其余实例继续尝试失败。
我需要设置如下:
. . .
<amq:broker dataDirectory="${activemq.directory}/data" id="broker" persistent="true" useJmx="false" >
. . .
我尝试了PropertyPlaceholderConfigurer,但据我了解,它从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。如果您想使用 PropertyPlaceholderConfigurer,一个非常讨厌(但至少有效)的解决方案是在开头添加一个空格。
<amq:broker useJmx="false" persistent="false">
<amq:transportConnectors>
<amq:transportConnector uri=" #{myconf.getConfigurationValue('JMS_URI')}" />
</amq:transportConnectors>
</amq:broker>
myconf.properties:JMS_URI=tcp://localhost:0?daemon=false
<强>2。同样有趣的是,如果您至少显式设置协议(protocol),那么它也可以工作:
<amq:broker useJmx="false" persistent="false">
<amq:transportConnectors>
<amq:transportConnector uri="tcp://#{myconf.getConfigurationValue('JMS_URI')}" />
</amq:transportConnectors>
</amq:broker>
myconf.properties:JMS_URI=localhost:0?daemon=false
关于java - ActiveMQ 配置和 Spring 表达式语言 (SpEL),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10096703/