2
votes

I am trying to fetch a property from the properties file in java code written in mule.

Class Example {
@NotBlank("message" = "${prop1}")
String key1;
String key2;
}

prop1 is a property stored in properties file

prop1 = " 001 | key1 cannot be blank"

I want prop1 to be resolved as 001 | key1 cannot be blank. ${propname} doesn't work. I can't use the value annotation as I want to save the value of the property in the message.

1
Is the question for Mule 3 or Mule 4? - aled
@aled it is for Mule 4 - HMT

1 Answers

1
votes

The best approach for this is to not depend on any Mule specific code and deal with the property as you would any other argument, just passing it as a parameter. So when instantiating or calling a certain method, you'd just pass in the property at the Mule side:

<java:new class="com.me.Person" constructor="Person(String, Integer)">
    <java:args>#[{
      name: Mule::p('prop1'),
      age: 30
    }]</java:args>
</java:new>

Otherwise you'll depend on how that Java code is loaded since you'll need to inject a ConfigurationProperties instance and use it to resolve your property:

  @Inject
  private ConfigurationProperties configurationProperties;

  String getProperty(String name) {
     return configurationProperties.resolveStringProperty(name).orElse(null);
  }

This means your Java code has to be part of an SDK module so the injection takes place.