5

I'm using Mule 3 to query a database using JDBC, and I'd like to modify the query depending on input from a .properties file. I have this in my xml...

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

Getting the following exception...

Exception in thread "main" org.mule.module.launcher.DeploymentInitException: SAXParseException: The prefix "context" for element "context:property-placeholder" is not bound.

Do I need to include some special .xsd file?

Narabhut
  • 839
  • 4
  • 13
  • 30

5 Answers5

7

Add the xmlns namespace prefix and schema location to your Mule config mule element tag.

Prefix:

xmlns:context="http://www.springframework.org/schema/context"

SchemaLocation:

http://www.springframework.org/schema/context  http://www.springframework.org/schema/context/spring-context-3.0.xsd

It should look like as below.

Eg:

<mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:spring="http://www.springframework.org/schema/beans"      
    xmlns:http="http://www.mulesoft.org/schema/mule/http" 
    xmlns:context="http://www.springframework.org/schema/context"

    xsi:schemaLocation="
        http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.3/mule.xsd
        http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/3.3/mule-http.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
        http://www.springframework.org/schema/context  http://www.springframework.org/schema/context/spring-context-3.0.xsd      
        ">


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


  ...........  Other stuff



</mule>
user1760178
  • 6,277
  • 5
  • 27
  • 57
  • Thanks. That seems to have fixed the namespace issue but I'm getting a FileNotFound exception when the file clearly exists. Have you experienced this issue before? – Narabhut Jun 25 '13 at 20:08
  • Made a new question about this issue, here is the link http://stackoverflow.com/questions/17326783/filenotfound-exception-while-loading-from-a-properties-file-in-mule Please see if you can resolve – Narabhut Jun 26 '13 at 17:35
  • There is an answer posted for your question. Please try it. That should solve it. – user1760178 Jun 27 '13 at 13:52
4

I had the same issues and fixed it. Here what I did.

  1. Kept all .properties under src/main/resources
  2. < context:property-placeholder location="file.dev.properties,file.stage.properties" />
  3. Keeping all the files in classpath was a challenge. So Goto your project folder, Open .classpath file in text pad and add the below line

    < classpathentry 
      including="file.dev.properties|file.prod.properties|file.stage.properties"
      kind="src" path="src/main/resources"/ >
    
  4. Save, refresh and it works.
Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
0

Use the following xsd in xsi:schemaLocation --

http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-current.xsd

user1493140
  • 5,976
  • 4
  • 29
  • 49
  • I'm having the same exception. I should add that I'm placing the placeholder inside the mule tags itself, i.e. ` – Narabhut Jun 25 '13 at 18:35
0

The other answers covered the namespace issue, but I'll add that I found that the context:property-placeholder tag needed to be between "spring:beans" tags. Here's an example that presumes that the properties file sets a property named "jmsBrokerURL":

<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>

An alternate method of reading properties (and one I prefer) is to use the Spring "util:properties" tag to read properties into a Properties bean which you then refer to using Spring EL. Watch out in this case that you use the Spring EL "#{}" notation instead of "${}" to reference the object and its variables. Here's the above example modified for that technique:

<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>

I like this latter approach mainly because I can deal with multiple properties files and included application context files more easily. The context:property-placeholder tag can be problematic when dealing with either multiple property files or when including an application context file within another.

RichW
  • 2,004
  • 2
  • 15
  • 24
0

Just put the properties file under resource folder and

Use this " classpath:settings.properties " in the property-placeholder and it will work ...

Anirban Sen Chowdhary
  • 8,233
  • 6
  • 39
  • 81