Q:

utf8 charset with Thymeleaf

When using Spring with Thymeleaf all my Cyrillic characters are shown as ????? on pages.
Using 
@RequestMapping(value = "/login", method = RequestMethod.GET, produces = "text/html; charset=utf-8")
as it was suggested here: https://stackoverflow.com/a/11866822/1479414 and here: https://stackoverflow.com/a/12023816/1479414 doesn't help. 
How to solve this issue?

A:

The answer can be found here:
Property characterEncoding should be explicitly set for templateResolver and ThymeleafViewResolver:
<bean id="templateResolver" class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
    ...
    <property name="characterEncoding" value="UTF-8"/>
    ...
</bean>

<bean class="org.thymeleaf.spring4.view.ThymeleafViewResolver">
    ...
    <property name="characterEncoding" value="UTF-8"/>
    ...
</bean>

A:

working for me. java config
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.projectName.controller")
public class MVCConfig implements WebMvcConfigurer, ApplicationContextAware {

    @Autowired
    private ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws 
         BeansException {
        this.applicationContext = applicationContext;
    }

    @Bean
    public ViewResolver viewResolver(){
        ThymeleafViewResolver thymeleafViewResolver = new ThymeleafViewResolver();
        thymeleafViewResolver.setTemplateEngine(templateEngine());
        thymeleafViewResolver.setCharacterEncoding("UTF-8");
       return thymeleafViewResolver;
    }

    @Bean
    public TemplateEngine templateEngine(){
       SpringTemplateEngine springTemplateEngine = new SpringTemplateEngine();
       springTemplateEngine.setEnableSpringELCompiler(true);
       springTemplateEngine.setTemplateResolver(templateResolver());
       return springTemplateEngine;
   }

   @Bean
   public ITemplateResolver templateResolver(){
       SpringResourceTemplateResolver springResourceTemplateResolver = new 
                        SpringResourceTemplateResolver();
       springResourceTemplateResolver.setApplicationContext(applicationContext);
       springResourceTemplateResolver.setPrefix("/WEB-INF/views/");
       springResourceTemplateResolver.setTemplateMode(TemplateMode.HTML);
       springResourceTemplateResolver.setSuffix(".html");
       springResourceTemplateResolver.setCharacterEncoding("UTF-8");
       return springResourceTemplateResolver;
  }

   @Override
   public void addResourceHandlers(ResourceHandlerRegistry registry) {
      registry
            .addResourceHandler("/resources/**")
            .addResourceLocations("/resources/");
   }
}

