Spring Boot + Thymeleaf not finding message properties

前端 未结 2 1236
野趣味
野趣味 2021-01-12 17:32

I am trying to create a web application using Spring Boot and Thymeleaf and am having trouble getting the template to use the messages defined in a properties file. Instead

相关标签:
2条回答
  • 2021-01-12 17:39

    I Have the same Issue while using messages.properties file The issue was @EnableAutoConfiguration not added in my Spring boot file

     @SpringBootApplication
     @EnableAutoConfiguration
        public class Run {
    
            public static void main(String[] args) {
                SpringApplication.run(Run.class, args);
                System.out.println("Run");
            }
    
        }
    

    After added its work

    0 讨论(0)
  • 2021-01-12 17:40

    I believe that changing the name of form.properties to messages.properties and locating it in the root of your resources folder should allow spring boot to pick it up automagically.

    When I have multiple message files I explicitly list them in a MessageSource bean so that the MVC auto-configuration picks them up, e.g.:

    @Bean
    public MessageSource messageSource() {
        final ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
        messageSource.setBasenames("classpath:/some-mvc-messages", "classpath:/some-other-mvc-messages", "classpath:/another-projects/mvc-messages");
        messageSource.setUseCodeAsDefaultMessage(true);
        messageSource.setDefaultEncoding("UTF-8");
        messageSource.setCacheSeconds(5);
        return messageSource;
    }
    
    0 讨论(0)
提交回复
热议问题