2

I need to set the global property grammatically. Functionally it should do exactly what the following statement should be doing

<global-property name="host-name" value="localhost" doc:name="Global Property"/>

I believe I should be able to access this property using ${host-name}. In this specific scenarion I don't want to load the property from properties file.

lalli
  • 6,083
  • 7
  • 42
  • 55
user1493140
  • 5,976
  • 4
  • 29
  • 49

1 Answers1

2

If you just want to resolve placeholders like ${host-name} you can extend the Spring PropertyPlaceholderConfigurer class with a custom implementation of method resolvePlaceholder, and add it as a Spring bean like this:

<spring:beans>
  <spring:bean id="myConfigurer" class="my.test.MyConfigurer"/>
</spring:beans>

Your custom resolvePlaceholder is then called to resolve any unresolved properties.

It is also fairly simple to set actually set properties in the Mule context registry by getting the context from a message (message.getMuleContext()) or by implementing a MuleContextAware bean, but in those cases the property will not yet be available at the time when the property placeholders are resolved.

You would set the property like this:

context.getRegistry().registerObject("myKey", "myVal")

and access it later like this:

context.getRegistry().get("myKey")
Anton Kupias
  • 3,945
  • 3
  • 16
  • 20