I encountered some encoding problems in learning Spring Boot; I want to add a CharacterEncodingFilter like Spring 3.x. just like this:
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Since Spring Boot 1.4.2 registering your own CharacterEncodingFilter will work ONLY IF you disable Spring's own instance of this bean by setting
spring.http.encoding.enabled=false
in the application.properties.However, one can resolve this matter without any Filter instantiation by adding these setting to the application.properties:
Source: Appendix A. Common application properties
I think there is no need to explicity write the following properties in application.properties file:
spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
spring.http.encoding.force=true
Instead if you go to pom.xml in your application and if you have the following, then spring will do the needful.
Example code for your Application.java class, as proposed in the comments above: