0

I'm a using spring boot (2.5.7) with the devtools dependency for hot reload. It works pretty well (including changes in fragments) but not for the localisation files (message_XX.properties under resources/lang). Every time I make a change there, I need to restart the server. Here is my application.yaml:

spring:
  thymeleaf:
    cache: false
    mode: HTML
    encoding: UTF-8
    prefix: file:src/main/resources/templates/
  web:
    resources:
      static-locations:
        - file:src/main/resources/static/
      cache:
        period: 0

Some edits:

  • I use vscode and gradle 7
  • I redefined a MessageSource.

Any idea?

Thanks!

Fabian
  • 133
  • 1
  • 8
  • See https://stackoverflow.com/a/45757497/3728901 – Vy Do Nov 22 '21 at 07:30
  • Your locatiuons are wrong there is no `src/main/resources` and you are actually overwriting the defaults (which already point there). There is nothing in your config regarding messages although you did change the defaults (or maybe even have declared your own `MessageSource` instead of using the default one). – M. Deinum Nov 22 '21 at 07:48
  • @DoNhuVy, I'm not using IntelliJ, so this does not help (I use VSCode, but build things with grade manually). – Fabian Nov 23 '21 at 08:57
  • @M.Deinum, yes I redefined a `MessageSource` to point to a `lang` folder. But I do have a folder `src/main/resources` where the `static` and `templates` files are. If I remove that line from the `yaml` file, hot reload does not work for templates file. – Fabian Nov 23 '21 at 09:09
  • Depending on which `MessageSource` caching might or might not work. You should set the cache time to 0 (no-cache). Well `src/main/resources` is the classpath. If you leave this configuration and deploy a jar file (or war) your application won't run anymore. Disable caching and doing an auto build in your IDE should make reloading work. See https://attacomsian.com/blog/spring-boot-auto-reload-thymeleaf-templates (method 1) if you are on Intellij or netbeans. – M. Deinum Nov 23 '21 at 09:27

1 Answers1

0

Forgot to reply earlier, in the end, I simply came back to:

spring:
  thymeleaf:
    cache: false
    mode: HTML
    encoding: UTF-8
  cache:
    period: 0

My LocaleConfig class:

@Configuration
public class LocaleConfig {
    @Bean
    public AcceptHeaderLocaleResolver localeResolver() {
        final AcceptHeaderLocaleResolver resolver = new AcceptHeaderLocaleResolver();
        resolver.setDefaultLocale(Locale.ENGLISH);
        return resolver;
    }

    @Bean
    public ResourceBundleMessageSource messageSource() {
        final ResourceBundleMessageSource source = new ResourceBundleMessageSource();
        source.setBasename("lang/message");
        return source;
    }
}

And then, I need two terminals, one with a continuous build from gradle and one with the spring boot bootRun task:

./gradlew compileJava --continuous

and

./gradlew bootRun

DISCLAIMER: it may happen that I need to stop and restart both as the new messages are sometimes not picked up.

Fabian
  • 133
  • 1
  • 8