2014-01-10 43 views
0

我想在我部署的Mule應用程序的外部使用log4j.properties文件(它將以不同的名稱命名)。該應用程序使用MMC服務器進行部署。在我的IDE的測試環境中,如果我設置虛擬機arg -Dlog4j.configuration=file:///c:/esb/etc/log4jconfig/log4j.myApp.properties,指向外部log4j屬性文件,它將起作用。如何在Mule MMC部署的應用程序初始化其log4j設置之前設置系統屬性?

但是,在部署到Mule MMC分段環境時,獲取相同的應用程序以加載外部log4j屬性文件尚未運行。

Maven Surefire插件將工作,但這是測試環境。

我曾嘗試:

<plugin> 
     <groupId>org.codehaus.mojo</groupId> 
     <artifactId>properties-maven-plugin</artifactId> 
     <version>1.0-alpha-2</version> 
     <executions> 
      <execution> 
       <goals> 
        <goal>set-system-properties</goal> 
       </goals> 
       <configuration> 
        <properties> 
         <property> 
          <name>my.property.name</name> 
          <value>my.property.value</value> 
         </property> 
        </properties> 
       </configuration> 
      </execution> 
     </executions> 
    </plugin> 

我也曾嘗試:

<plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>exec-maven-plugin</artifactId> 
      <version>1.2.1</version> 
      <executions> 
       <execution> 
        <goals> 
         <goal>java</goal> 
        </goals> 
       </execution> 
      </executions> 
      <configuration> 
       <!--<mainClass>${exec.main-class}</mainClass>--> 
       <systemProperties> 
        <systemProperty> 
         <value>file:///c:/esb/etc/log4jconfig/log4j.myApp.properties</value> 
        </systemProperty> 
       </systemProperties> 
      </configuration> 
     </plugin> 

我已經在IDE中測試這些配置也打包並部署到沒有成功分段騾MMC服務器。我也嘗試爲屬性值提供七種不同的命名約定,Log4J在初始化時轉換爲URL。

我們正在使用log4j-1.2.16。查看log4j手冊http://logging.apache.org/log4j/1.2/manual.html,默認初始化程序,我被告知設置log4j.configuration系統屬性將會覆蓋日誌屬性文件的位置,並且它的確如此,正如我所說的,當我更改虛擬機參數在IDE測試中。

我需要一種方式來讓騾子在log4j初始化之前加載該系統屬性。

在MMC中部署的Mule應用程序與其他幾個已部署的應用程序共享相同的Mule獨立實例,並且我不想將所有這些應用程序的日誌位置更改爲同一位置。每個應用都必須有自己的。

回答

0

您可以通過添加以下bean來你的配置實現這一目標:

<spring:bean id="log4jInitialization" 
     class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"> 
     <spring:property name="targetClass" value="org.springframework.util.Log4jConfigurer" /> 
     <spring:property name="targetMethod" value="initLogging" /> 
     <spring:property name="arguments"> 
      <spring:list> 
       <spring:value>file:///c:/esb/etc/log4jconfig/log4j.myApp.properties</spring:value> 
      </spring:list> 
     </spring:property> 
</spring:bean> 
+0

謝謝你,做到了。完美的作品! – user3182305

相關問題