I'm using a custom made MessageSource on a spring boot application
to retreive both local version messages.properties, messages_fr.properties, messages_it.properties, messages_es.properties and a remote version from an accessible http file access
http://example.com/extmessages.properties, http://example.com/extmessages_fr.properties ...etc
It works fine for the default Locale EN language messages.properties and extmessages.properties are found.
the problem is for other languages.
i m using this code to initialise my messageSource:
@Bean
public ReloadableResourceBundleMessageSource messageSource() throws IOException {
ReloadableResourceBundleMessageSource messageSource= new ReloadableResourceBundleMessageSource();;
String baseName = "messages";
messageSource.setBasenames(baseName, "http://example.com/ext" + baseName);
messageSource.setDefaultEncoding(StandardCharsets.UTF_8.name());
//System.out.println(messageSource.getMessage("mail.object", null, Locale.ITALY)); /*<- where the problem is resolved */
return messageSource;
}
I'm using @Autowired to link to the MessageSource in other part in the code.
@Autowired
private MessageSource messageSource;
my problem is that each time i use
messageSource.getMessage("mail.object", null, Locale.ITALY) => i get the default message resolution to default witch is ENGLISH (messages.properties and extmessages.properties)
and its the same for all other locales, unless it is called within the block of initialisation of the messageSource (commented line), the messageSource will keep answering the default. However, if i manage to call it in the initialisation, the langage Local is loaded and works fine with the loaded version in my case Locale.ITALY
it seems to me that there is a bug somewhere on how the ReloadableResourceBundleMessageSource resolved the Local extension or cache,
i tested many things with no caching to faultback system actif & inactif
The only workaround that i found is:
To perform a blanc call to a property with all needed local within the initialisation phase, however it doesn't same as a good extensible solution.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…