0

I found ReloadableResourceBundleMessageSource in spring framework reference

As an alternative to ResourceBundleMessageSource, Spring provides a ReloadableResourceBundleMessageSource class. This variant supports the same bundle file format but is more flexible than the standard JDK based ResourceBundleMessageSource implementation. In particular, it allows for reading files from any Spring resource location (not just from the classpath) and supports hot reloading of bundle property files (while efficiently caching them in between). Check out the ReloadableResourceBundleMessageSource javadocs for details.

If I understand it correctly, you can change codes in properties files and server will load them instantly at runtime.

How can one achieve hot reload in spring boot based web application?

What is the trigger of hot reload?

Patrik Mihalčin
  • 3,341
  • 7
  • 33
  • 68

1 Answers1

0

You can create a bean of ReloadableResourceBundleMessageSource like this

@Bean
public ReloadableResourceBundleMessageSource messageSource() {
    ReloadableResourceBundleMessageSource source = new ReloadableResourceBundleMessageSource();
    source.setBasename("classpath:test");  // name of the resource bundle
    source.setDefaultEncoding("UTF-8");
    source.setCacheSeconds(10);
    return source;
}

To use it you can just autowire MessageSource in your class and get messages from the bundle.

@Autowired
MessageSource messageSource;

public void getMessage() {
   Locale locale = LocaleContextHolder.getLocale();
   String message = messageSource.getMessage("some.message", null, locale);
}

The MessageSource is different from PropertySource. Now, if you are talking about reloading properties that are used to configure spring (like in application.properties), then look here

raiyan
  • 821
  • 6
  • 15