MULE ESB 3.3 - Your java component reading properties from a property file
The problem:
I had a mule XML configuration file defining some property files that is loaded by mule container, like this:
<context:property-placeholder location="classpath:my-mule-app.properties,classpath:my-mule-app-override.properties" />
and I I had a java component that need to read the value of a property called jbc.url. That property is on my my-mule-app.properties.
Ok, I am pretty sure there are a few other ways to solve this problem but I came up with a very simple solution for that so I want to share (besides that, several ways that I found on the web did not work for me, including using @Value from Spring or using the registry from muleContext).
Anyways, here is what worked:
This is what I had to add on the flow file configuration file when declaring my java component:
<component doc:name="AgeHandler">
<singleton-object class="com.citi.isg.java.components.AgeHandler">
<property value="${jdbc.url}"
key="jdbcUrl" />
</singleton-object>
</component>
And this is a sniped of my AgeHandler.java:
public class AgeHandler {
private String jdbcUrl;
public void setJdbcUrl(String url) { this.jdbcUrl = url; }
.....
}
That is all you need. Mule/Spring will invoke setJdbcUrl when the component is called to perform the injection of the property jdbc.url into the local field jdbcUrl.
Good luck!
I had a mule XML configuration file defining some property files that is loaded by mule container, like this:
<context:property-placeholder location="classpath:my-mule-app.properties,classpath:my-mule-app-override.properties" />
and I I had a java component that need to read the value of a property called jbc.url. That property is on my my-mule-app.properties.
Ok, I am pretty sure there are a few other ways to solve this problem but I came up with a very simple solution for that so I want to share (besides that, several ways that I found on the web did not work for me, including using @Value from Spring or using the registry from muleContext).
Anyways, here is what worked:
This is what I had to add on the flow file configuration file when declaring my java component:
<component doc:name="AgeHandler">
<singleton-object class="com.citi.isg.java.components.AgeHandler">
<property value="${jdbc.url}"
key="jdbcUrl" />
</singleton-object>
</component>
And this is a sniped of my AgeHandler.java:
public class AgeHandler {
private String jdbcUrl;
public void setJdbcUrl(String url) { this.jdbcUrl = url; }
.....
}
That is all you need. Mule/Spring will invoke setJdbcUrl when the component is called to perform the injection of the property jdbc.url into the local field jdbcUrl.
Good luck!
Comments
Post a Comment