Reputation: 10455
For unit test purposes I am trying to create a Spring MessageSource from Java code, but all examples and docs I can find only tell me how to do it in Spring.
Can anybody give me a hint?
The message property files are in /src/main/resources/com/neopost/cim/i18n/text/
Upvotes: 0
Views: 2300
Reputation: 21883
You can just do the following in your Java code;
MessageSource messageSource = new ReloadableResourceBundleMessageSource();
messageSource.setCacheSeconds(5);
messageSource.setDefaultEncoding("UTF-8");
messageSource.setFallbackToSystemLocale(true);
messageSource.setUseCodeAsDefaultMessage(true);
messageSource.setBasenames(Arrays.asList("classpath:com\neopost\cim\i18n\text\message"));
Your message files should be named message.properties
and must be placed inside com\neopost\cim\i18n\text\
messageSource.getMessage*
methods to call and get messages.
Upvotes: 5