How to configure CharacterEncodingFilter in SpringBoot?

后端 未结 4 1209
暗喜
暗喜 2020-12-08 07:02

I encountered some encoding problems in learning Spring Boot; I want to add a CharacterEncodingFilter like Spring 3.x. just like this:


    <         


        
4条回答
  •  攒了一身酷
    2020-12-08 08:04

    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:

    # Charset of HTTP requests and responses. Added to the "Content-Type" header if not set explicitly.
    spring.http.encoding.charset=UTF-8
    # Enable http encoding support.
    spring.http.encoding.enabled=true
    # Force the encoding to the configured charset on HTTP requests and responses.
    spring.http.encoding.force=true
    

    Source: Appendix A. Common application properties

提交回复
热议问题