Mule 3-从.properties文件加载

Mule 3-从.properties文件加载,mule,mule-studio,Mule,Mule Studio,我使用Mule3使用JDBC查询数据库,我想根据.properties文件的输入修改查询。我的xml中有这个 <context:property-placeholder location="C:\path\to\file\settings.properties" /> 我需要包括一些特殊的.xsd文件吗?在xsi:schemaLocation中使用以下xsd-- 将xmlns名称空间前缀和模式位置添加到Mule config Mule元素标记中 前缀: xmlns:context=

我使用Mule3使用JDBC查询数据库,我想根据.properties文件的输入修改查询。我的xml中有这个

<context:property-placeholder location="C:\path\to\file\settings.properties" />

我需要包括一些特殊的.xsd文件吗?

在xsi:schemaLocation中使用以下xsd--


将xmlns名称空间前缀和模式位置添加到Mule config Mule元素标记中

前缀:

xmlns:context="http://www.springframework.org/schema/context"
方案位置:

http://www.springframework.org/schema/context  http://www.springframework.org/schema/context/spring-context-3.0.xsd
它应该如下所示

例如:


...........  其他东西

其他答案涵盖了名称空间问题,但我要补充的是,我发现context:property占位符标记需要位于“spring:beans”标记之间。下面的示例假定属性文件设置了一个名为“jmsBrokerURL”的属性:


读取属性的另一种方法(也是我更喜欢的方法)是使用Spring“util:properties”标记将属性读取到属性bean中,然后使用Spring EL引用该bean。在这种情况下,请注意使用Spring EL“#{}”符号而不是“${}”来引用对象及其变量。下面是针对该技术修改的上述示例:

<mule xmlns="http://www.mulesoft.org/schema/mule/core" version="EE-3.4.0"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
      xmlns:spring="http://www.springframework.org/schema/beans"
      xmlns:util="http://www.springframework.org/schema/util"
      xsi:schemaLocation="
          http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
          http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd">

    <spring:beans>
        <util:properties id="myConfig"  location="C:/path/to/file/settings.properties" />
        <spring:bean name="myConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
            <spring:property name="brokerURL" value="#{myConfig.jmsBrokerURL}" /> <!-- Note the pound (hash) symbol. -->
        </spring:bean>
    </spring:beans>

    <flow name="MyFlow" doc:name="MyFlow">
        <!-- Flow configuration here. -->
    </flow>

</mule>


我喜欢后一种方法,主要是因为我可以更轻松地处理多个属性文件和包含的应用程序上下文文件。当处理多个属性文件或在另一个属性文件中包含应用程序上下文文件时,context:property占位符标记可能会出现问题。

只需将属性文件放在资源文件夹下,然后


在属性占位符中使用这个“classpath:settings.properties”,它将起作用…

我也遇到了同样的问题,并修复了它。这就是我所做的

  • 将所有.properties保存在src/main/resources下
  • 将所有文件保存在类路径中是一项挑战。所以转到项目文件夹,在文本板中打开.classpath文件并添加下面的行

    < classpathentry 
      including="file.dev.properties|file.prod.properties|file.stage.properties"
      kind="src" path="src/main/resources"/ >
    
  • 保存,刷新,它的工作
    我也有同样的例外。我应该补充一点,我将占位符放在mule标签本身内,即
    谢谢。这似乎已经解决了名称空间问题,但当文件明显存在时,我得到了一个FileNotFound异常。你以前有没有遇到过这个问题?提出了一个关于这个问题的新问题,这是一个链接,请查看你是否能解决这个问题。你的问题有一个答案。请试一试。这应该可以解决问题。
    
    <mule xmlns="http://www.mulesoft.org/schema/mule/core" version="EE-3.4.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
          xmlns:spring="http://www.springframework.org/schema/beans"
          xmlns:context="http://www.springframework.org/schema/context"
          xsi:schemaLocation="
              http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
              http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
              http://www.springframework.org/schema/context  http://www.springframework.org/schema/context/spring-context-3.0.xsd">
    
        <spring:beans>
            <context:property-placeholder location="C:/path/to/file/settings.properties" />
            <spring:bean name="myConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
                <spring:property name="brokerURL" value="${jmsBrokerURL}" />
            </spring:bean>
        </spring:beans>
    
        <flow name="MyFlow" doc:name="MyFlow">
            <!-- Flow configuration here. -->
        </flow>
    
    </mule>
    
    <mule xmlns="http://www.mulesoft.org/schema/mule/core" version="EE-3.4.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
          xmlns:spring="http://www.springframework.org/schema/beans"
          xmlns:util="http://www.springframework.org/schema/util"
          xsi:schemaLocation="
              http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
              http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
              http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd">
    
        <spring:beans>
            <util:properties id="myConfig"  location="C:/path/to/file/settings.properties" />
            <spring:bean name="myConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
                <spring:property name="brokerURL" value="#{myConfig.jmsBrokerURL}" /> <!-- Note the pound (hash) symbol. -->
            </spring:bean>
        </spring:beans>
    
        <flow name="MyFlow" doc:name="MyFlow">
            <!-- Flow configuration here. -->
        </flow>
    
    </mule>
    
    < classpathentry 
      including="file.dev.properties|file.prod.properties|file.stage.properties"
      kind="src" path="src/main/resources"/ >