DEV Community

Clavin June
Clavin June

Posted on • Originally published at clavinjune.dev on

Force Set Character Encoding On Spring Boot

Add this on your spring boot project:

@Bean
@Order(Ordered.HIGHEST_PRECEDENCE)
public FilterRegistrationBean<CharacterEncodingFilter> characterEncodingFilterRegistration() {
  CharacterEncodingFilter filter = new CharacterEncodingFilter();
  filter.setEncoding("UTF-8"); // use your preferred encoding
  filter.setForceEncoding(true); // force the encoding

  FilterRegistrationBean<CharacterEncodingFilter> registrationBean =
    new FilterRegistrationBean<>(filter); // register the filter
  registrationBean.addUrlPatterns("/*"); // set preferred url
  return registrationBean;
}

Enter fullscreen mode Exit fullscreen mode

reference

Top comments (1)

Collapse
 
partho63 profile image
Partho Das

Hello, Calvin June.
I am working in a Spring Boot application. I have added this code snippet in my Application.java class. But my character encoding is not fixed yet. If I submit বাংলা it is saved as মোঃ মিজানুর রহমান

Can you help me regarding this encoding, please? Can you show me the full procedure?