SpringBoot2.1.3修改tomcat参数支持请求特殊符号

最近遇到一个问题,比如GET请求中,key,value中带有特殊符号,请求会报错,见如下URL:

http://xxx.xxx.xxx:8081/aaa?key1=val1&a.[].id=123&b=a[1]

现在,我们进入boot启动类,添加如下代码即可:

 

public class DemoApp {

    public static void main(String[] args) {

           SpringApplication.run(DemoApp.class, args);

    }

    @Bean

    public TomcatServletWebServerFactory webServerFactory() {

          TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();

          factory.addConnectorCustomizers(new TomcatConnectorCustomizer() {

                            @Override

                            public void customize(Connector connector) {

                                   connector.setProperty("relaxedPathChars", "\"<>[\\]^`{|}");

                                   connector.setProperty("relaxedQueryChars", "\"<>[\\]^`{|}");

                             }

            });

            return factory;

    }

}

posted @ 2019-05-06 10:57  JimmyShan  阅读(3903)  评论(1编辑  收藏  举报