Many answers to this question on the Internet are to modify the Tomcat configuration file, but we are a springboot project, and Tomcat is built-in, so simply modifying the Tomcat configuration file is useless. It only takes a very simple piece of code to solve this problem.
Pay attention to my main class
@SpringBootApplication
public class Application {
@Bean
public ConfigurableServletWebServerFactory webServerFactory() {
TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
factory.addConnectorCustomizers(
(TomcatConnectorCustomizer) connector -> connector.setProperty("relaxedQueryChars", "|{}[]\\")
);
return factory;
}
public static void main(String[] args){
SpringApplication.run(Application.class, args);
}
}
Just add the following code in the main class and it will be fine
@Bean
public ConfigurableServletWebServerFactory webServerFactory() {
TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
factory.addConnectorCustomizers(
(TomcatConnectorCustomizer) connector -> connector.setProperty("relaxedQueryChars", "|{}[]\\")
);
return factory;
}