【问题标题】:log4j2.xml configuration from file for mule applications in mule 3.6.2来自 mule 3.6.2 中 mule 应用程序文件的 log4j2.xml 配置
【发布时间】:2015-10-29 19:45:23
【问题描述】:

如何从特定文件(如“/opt/applications/app1/log/config/log4j2.xml”)中获取 mule 3.6.2 中 mule 应用程序的配置。常用的方法是从配置文件 log4j2.xml 中获取配置,该配置文件存储在资源文件夹中,我们需要从其他外部路径读取此配置文件。

【问题讨论】:

    标签: mule log4j2


    【解决方案1】:

    默认情况下,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> 
    

    【讨论】:

    • 那是不是需要导入一个应用上下文呢?或者我可以在mule config文件中进行配置?
    • 是的,可以在mule配置文件中配置,但我建议你分开Mule。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-31
    • 1970-01-01
    • 2017-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多