How to display messages in Thymeleaf and Spring Boot?

后端 未结 5 1868
深忆病人
深忆病人 2021-02-01 05:58

I created a Spring Boot web application that uses Thymeleaf as the template engine. I configured the MessageSource to look for messages in a subfolder:



        
5条回答
  •  北荒
    北荒 (楼主)
    2021-02-01 06:22

    The way I resolved the i18n messaging was to define the MessagesSource bean like you. Additionally I had to override the getValidator() method of the WebMvcConfigurerAdapter.

    @Override
    public Validator getValidator() {
        LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
        validator.setValidationMessageSource( messageSource() );
        return validator;
    }
    

    After this, it worked for me.

提交回复
热议问题