Invalid character found in the request target in spring boot

According to https://tomcat.apache.org/tomcat-8.5-doc/config/systemprops.html, requestTargetAllow is deprecated. For me, the other solutions presented here did not work either. According to the Tomcat documentation I found a way to set the property relaxedQueryChars instead:

@Bean
public ConfigurableServletWebServerFactory webServerFactory() {
    TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
    factory.addConnectorCustomizers(new TomcatConnectorCustomizer() {
        @Override
        public void customize(Connector connector) {
            connector.setProperty("relaxedQueryChars", "|{}[]");
        }
    });
    return factory;
}

you will start your Spring boot app like this

$ java -jar -Dtomcat.util.http.parser.HttpParser.requestTargetAllow=|{}
 demo-0.0.1-SNAPSHOT.jar

or encode uri like this

document.location = restUrl + "/print?reportParams= " + encodeURI(JSON.stringify(jsonData));

For a Spring Boot (2.X) application, just add to properties file:

server.tomcat.relaxed-query-chars=|,{,},[,]

There is also the following key: server.tomcat.relaxed-path-chars