I have spring boot application using i18n that imports a jar file as a library.
In jar library there are messages.properties files messages.properties, messages_en.properties, ...
that I want to use.
Problem is that messages.properties
files from the library are not loaded and I can't use translations from them.
I have MessageSource bean set up as bellow and I can't figure out what path should I add to access messages.properties
files in the library. Now only messages.properties files from the main app are used
@Bean
public MessageSource messageSource() {
ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
messageSource.setBasenames(
"classpath:messages",
// " path to messages in library ?"
);
messageSource.setUseCodeAsDefaultMessage(true);
messageSource.setDefaultEncoding("UTF-8");
return messageSource;
}
Messages in the library were added to resources, so they are in the base folder of the jar
I have managed to find a solution. I have changed name of messages in one project so they were not the same as names in the other. F.eg.: messages.properties, messages_en.properties in one project and messages2.properties, messages2_en.properties in second project (library).
Than i've added path to messages and messages2 in configuration as bellow and all messages were accessible.
@Bean
public MessageSource messageSource() {
ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource ();
messageSource.setBasenames("classpath:messages", "classpath:messages2");
return messageSource;
}
It comes out that messages files names can't be the same