How can I get the configuration from a specific file like '/opt/applications/app1/log/config/log4j2.xml' for a mule application in mule 3.6.2. The common way is to get the configuration from a config file log4j2.xml which is stored in the resource folder, we need to read this configuration file from other external path.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
By default, Mule use its own log4j2 file for logging. To read log4j2.xml configuration file from external path, add the next beans in your file Application Context, For that specify the external file to be used in the context General of Mule.
Application Context:
<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>
Then you need to import this context from your file Mule flow, with:
Mule Config
<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>