SpringBoot 内嵌tomcat设置解决报错问题

2022-02-10 14:54:52 浏览数 (1)

解决报错:

Invalid character found in the request target. The valid characters are defined in RFC****

代码语言:javascript复制
 //2.x
    @Bean
    public ConfigurableServletWebServerFactory webServerFactory() {
        TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
        factory.addConnectorCustomizers((TomcatConnectorCustomizer) connector -> 
        connector.setProperty("relaxedQueryChars", "|{}[]"));
        return factory;
    }

    //1.x
    @Bean
    public EmbeddedServletContainerFactory webServerFactory() {
        TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();
        factory.addConnectorCustomizers(
                (TomcatConnectorCustomizer) connector -> 
                connector.setProperty("relaxedQueryChars", "|{}[]"));
        return factory;
    }

    

0 人点赞