[英]How to load property file values dynamically in apache camel + spring
我是春天使用駱駝2.17的新手。 我有一個處理器從Web服務接收錯誤代碼,我在屬性文件中配置了錯誤描述,如
myproject.errorCode=1001:error1 description, 1002:error2 description, 1003:....
目前我正在使用屬性注入讀取值myproject.errorCode並解析所有帶有描述的errorCode工作正常。 但是錯誤代碼列表非常龐大並且將其保存在單個屬性中非常困難。 所以我想分割像這樣的屬性
myproject.errorCode.1001=error1 description
myproject.errorCode.1002=error2 description
myproject.errorCode.1003=error3 description
.....
我想根據從Web服務收到的錯誤代碼讀取我的處理器類中的屬性
String errorCodeRecieved = myWebService.getErrorCode();
String errorString = "myproject.errorCode.";
String errorDescription = something.getProperty(errorString + errorCodeRecieved);
我怎樣才能實現這一目標。 提前致謝
您可以在上下文中使用MessageSource ,
@Bean
MessageSource myMessageSource() {
ResourceBundleMessageSource r = new ResourceBundleMessageSource();
r.setBasenames("/messages/sample");
r.setDefaultEncoding("UTF-8");
return r;
}
然后在處理器中使用它來獲取相應的消息,如:
messageSource.getMessage(code, null, null, locale)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.