How to dynamically load property file values ​​in apache camel + spring

I'm a newbie using camel 2.17 with spring. I have a processor that receives an error code from a web service and I have configured an error description in a properties file, like

  myproject.errorCode=1001:error1 description, 1002:error2 description, 1003:....

      

I am currently reading the myproject.errorCode value using property injection and parsing the entire error code with a description, which works fine. But the list of error codes is very long, and it is very difficult to maintain it in one property. So I want to break properties like

   myproject.errorCode.1001=error1 description
   myproject.errorCode.1002=error2 description
   myproject.errorCode.1003=error3 description
   .....

      

and I want to read a property in my processor class according to the error code received from the web service like

  String errorCodeRecieved  = myWebService.getErrorCode();
  String errorString = "myproject.errorCode.";
  String errorDescription = something.getProperty(errorString + errorCodeRecieved);

      

How can I achieve this remedy. thanks in advance

+3


source to share


1 answer


you can make the MessageSource available in your context,

@Bean
MessageSource myMessageSource() {
    ResourceBundleMessageSource r = new ResourceBundleMessageSource();
    r.setBasenames("/messages/sample");
    r.setDefaultEncoding("UTF-8");
    return r;
}

      



And then use that in your cpu to get the appropriate message, like:

messageSource.getMessage(code, null, null, locale)

      

+2


source







All Articles