相关文章推荐
没有腹肌的开水瓶  ·  Exception in thread ...·  5 天前    · 
千年单身的蚂蚁  ·  Exception in thread ...·  5 天前    · 
咆哮的小蝌蚪  ·  java ...·  9 月前    · 
大气的芒果  ·  leaflet ...·  10 月前    · 
含蓄的高山  ·  centos 编译python3.7.0 ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

How can I set relaxedQueryChars for Spring Boot embedded Tomcat?

The connector attribute described here , but Spring Boot documentation has no such parameter listed.

How to set Tomcat's Connector attributes in general?

I am not sure if you can do this with properties file. I believe this should work

@Component
public class MyTomcatWebServerCustomizer
        implements WebServerFactoryCustomizer<TomcatServletWebServerFactory> {
    @Override
    public void customize(TomcatServletWebServerFactory factory) {
        factory.addConnectorCustomizers(new TomcatConnectorCustomizer() {
            @Override
            public void customize(Connector connector) {
                connector.setAttribute("relaxedQueryChars", "yourvaluehere");
                Correct, but might be simplified with lambda factory.addConnectorCustomizers(connector -> connector.setAttribute("relaxedQueryChars", "yourvaluehere"))
– Alex Karasev
                Aug 6, 2018 at 9:04
                may worth mentioning that connector.setAttribute was deprecated in 8, 9 and completely removed in 10 tomcat.apache.org/tomcat-8.5-doc/api/org/apache/catalina/… tomcat.apache.org/tomcat-9.0-doc/api/org/apache/catalina/… tomcat.apache.org/tomcat-10.0-doc/api/org/apache/catalina/…
– HoaPhan
                Apr 22 at 13:55

If you are using Spring Boot 2.x then you need to use WebSeerverFactoryCustomizer as given below.

@Bean
public WebServerFactoryCustomizer<TomcatServletWebServerFactory> 
    containerCustomizer(){
    return new EmbeddedTomcatCustomizer();
private static class EmbeddedTomcatCustomizer implements WebServerFactoryCustomizer<TomcatServletWebServerFactory> {
    @Override
    public void customize(TomcatServletWebServerFactory factory) {
        factory.addConnectorCustomizers((TomcatConnectorCustomizer) connector -> {
            connector.setAttribute("relaxedPathChars", "<>[\\]^`{|}");
            connector.setAttribute("relaxedQueryChars", "<>[\\]^`{|}");

The simplest method is to configure the server (add a line to application.properties). You can add something like this:

server.tomcat.relaxed-path-chars=<,>,etc
  • Spring Documentation Comma-separated list of additional unencoded characters that should be allowed in URI paths. Only "< > [ \ ] ^ ` { | }" are allowed.*
  • @Bean
    public EmbeddedServletContainerCustomizer containerCustomizer(){
        return new MyCustomizer();
    private static class MyCustomizer implements EmbeddedServletContainerCustomizer {
        @Override
        public void customize(ConfigurableEmbeddedServletContainer factory) {
            if(factory instanceof TomcatEmbeddedServletContainerFactory) {
                customizeTomcat((TomcatEmbeddedServletContainerFactory) factory);
        void customizeTomcat(TomcatEmbeddedServletContainerFactory factory) {
            factory.addConnectorCustomizers((TomcatConnectorCustomizer) connector -> {
                connector.setAttribute("relaxedPathChars", "<>[\\]^`{|}");
                connector.setAttribute("relaxedQueryChars", "<>[\\]^`{|}");
            

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.