簡體   English   中英

ActiveMQ 配置和 Spring 表達式語言 (SpEL)

[英]ActiveMQ configuration and Spring Expression Language (SpEL)

我必須在具有持久嵌入式代理的同一台機器上啟動這項服務的多個實例(單獨的 JVM)。 所有配置文件都是預先生成的,並在服務啟動之前以編譯方式完成變量替換。 我在嘗試獲取 AMQ 數據目錄和 KahaDB 鎖的多個實例時遇到問題,顯然第一個實例成功獲取了鎖,而 rest 繼續嘗試失敗。

我需要這樣設置:

. . .
<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. 有趣的是,如果您至少明確設置了協議,那么它也可以工作:

<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

我最終只使用了很好的舊 PropertyPlaceholderConfigurer 並刪除了 SpEL 符號,它就像一個魅力。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM