Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mule 3 - Loading from .properties file

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?

like image 861
Narabhut Avatar asked Jun 25 '13 17:06

Narabhut


People also ask

How do I read properties file in Mule 3?

The most optimal way to read a Mule properties file from a flow is using the ${Key} expression. This approach will work well for reading data from a Mule app properties file. Here, we first have to store the data in the Mule app properties file, as shown below, and then we have to use the “Key” to read the value.

What is the use of .properties file?

properties is a file extension for files mainly used in Java-related technologies to store the configurable parameters of an application. They can also be used for storing strings for Internationalization and localization; these are known as Property Resource Bundles.


2 Answers

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>
like image 81
user1760178 Avatar answered Sep 30 '22 19:09

user1760178


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.
like image 39
user2502826 Avatar answered Sep 30 '22 21:09

user2502826