Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.6k views
in Technique[技术] by (71.8m points)

java - ReloadableResourceBundleMessageSource is not refreshed with new locales when used

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...