【发布时间】:2015-10-29 19:45:23
【问题描述】:
如何从特定文件(如“/opt/applications/app1/log/config/log4j2.xml”)中获取 mule 3.6.2 中 mule 应用程序的配置。常用的方法是从配置文件 log4j2.xml 中获取配置,该配置文件存储在资源文件夹中,我们需要从其他外部路径读取此配置文件。
【问题讨论】:
如何从特定文件(如“/opt/applications/app1/log/config/log4j2.xml”)中获取 mule 3.6.2 中 mule 应用程序的配置。常用的方法是从配置文件 log4j2.xml 中获取配置,该配置文件存储在资源文件夹中,我们需要从其他外部路径读取此配置文件。
【问题讨论】:
默认情况下,Mule 使用自己的 log4j2 文件进行日志记录。要从外部路径读取 log4j2.xml 配置文件,请在文件 Application Context 中添加下一个 beans,为此指定要在 Mule 的 General 上下文中使用的外部文件。
应用程序上下文:
<bean id="loggerContext" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetClass">
<value> org.apache.logging.log4j.LogManager</value>
</property>
<property name="targetMethod">
<value>getContext</value>
</property>
<property name="arguments">
<value>false</value>
</property>
</bean>
<bean id="loggerContext1" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject" ref="loggerContext" />
<property name="targetMethod">
<value>setConfigLocation</value>
</property>
<property name="arguments">
<value>${log4j.external.path}</value>
</property>
</bean>
<bean id="loggerContext2" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject" ref="loggerContext" />
<property name="targetMethod">
<value>reconfigure</value>
</property>
</bean>
然后你需要从你的文件 Mule 流中导入这个上下文,使用:
骡配置
<mule xmlns:https="http://www.mulesoft.org/schema/mule/https"
xmlns="http://www.mulesoft.org/schema/mule/core"
{..}
<!-- Add this: -->
<spring:beans>
<spring:import resource="classpath*:application-context.xml" />
</spring:beans>
{..}
<flow name="http-name" >
{..}
</flow>
</mule>
【讨论】: