Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

优化tomcat配置relaxedQueryChars方式,采用TomcatConnectorCustomizer来实现 #764

Merged
merged 3 commits into from
Oct 24, 2022

Conversation

bearBoy80
Copy link
Contributor

之前实现通过

   public ServletWebServerFactory webServerFactory() {
       TomcatServletWebServerFactory fa = new TomcatServletWebServerFactory();
       fa.addConnectorCustomizers(connector -> connector.setProperty("relaxedQueryChars", "[]{}"));
       return fa;
   }

实现后,我们无法实现TomcatConnectorCustomizer来配置tomcat的参数,同时导致springboot默认提供一些扩展无法使用,比如TomcatContextCustomizer、TomcatProtocolHandlerCustomizer。
SpringBoot 自动化装配TomcatServletWebServerFactory代码类org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryConfiguration.EmbeddedTomcat如下:

        @Bean
        TomcatServletWebServerFactory tomcatServletWebServerFactory(ObjectProvider<TomcatConnectorCustomizer> connectorCustomizers, ObjectProvider<TomcatContextCustomizer> contextCustomizers, ObjectProvider<TomcatProtocolHandlerCustomizer<?>> protocolHandlerCustomizers) {
            TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
            factory.getTomcatConnectorCustomizers().addAll((Collection)connectorCustomizers.orderedStream().collect(Collectors.toList()));
            factory.getTomcatContextCustomizers().addAll((Collection)contextCustomizers.orderedStream().collect(Collectors.toList()));
            factory.getTomcatProtocolHandlerCustomizers().addAll((Collection)protocolHandlerCustomizers.orderedStream().collect(Collectors.toList()));
            return factory;
        }

其实tomcat配置relaxedQueryChars,还可以通过实现WebServerFactoryCustomizer,并实现Ordered接口

@elunez elunez merged commit a330519 into elunez:master Oct 24, 2022
elunez added a commit to elunez/eladmin-mp that referenced this pull request Jul 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants