猿问

为嵌入式 Tomcat 设置“relaxedQueryChars”

如何设置relaxedQueryCharsSpring Boot 嵌入式 Tomcat?

此处描述的连接器属性,但 Spring Boot文档没有列出此类参数。

一般如何设置Tomcat的Connector属性?


蝴蝶不菲
浏览 2017回答 3
3回答

缥缈止盈

如果您使用的是 Spring Boot 2.x,那么您需要使用 WebSeerverFactoryCustomizer,如下所示。@Beanpublic WebServerFactoryCustomizer<TomcatServletWebServerFactory>&nbsp;&nbsp; &nbsp; containerCustomizer(){&nbsp; &nbsp; return new EmbeddedTomcatCustomizer();}private static class EmbeddedTomcatCustomizer implements WebServerFactoryCustomizer<TomcatServletWebServerFactory> {&nbsp; &nbsp; @Override&nbsp; &nbsp; public void customize(TomcatServletWebServerFactory factory) {&nbsp; &nbsp; &nbsp; &nbsp; factory.addConnectorCustomizers((TomcatConnectorCustomizer) connector -> {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; connector.setAttribute("relaxedPathChars", "<>[\\]^`{|}");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; connector.setAttribute("relaxedQueryChars", "<>[\\]^`{|}");&nbsp; &nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; }}

尚方宝剑之说

我这样做是对我来说可行的解决方案:@Beanpublic EmbeddedServletContainerCustomizer containerCustomizer(){&nbsp; &nbsp; return new MyCustomizer();}private static class MyCustomizer implements EmbeddedServletContainerCustomizer {&nbsp; &nbsp; @Override&nbsp; &nbsp; public void customize(ConfigurableEmbeddedServletContainer factory) {&nbsp; &nbsp; &nbsp; &nbsp; if(factory instanceof TomcatEmbeddedServletContainerFactory) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; customizeTomcat((TomcatEmbeddedServletContainerFactory) factory);&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }&nbsp; &nbsp; void customizeTomcat(TomcatEmbeddedServletContainerFactory factory) {&nbsp; &nbsp; &nbsp; &nbsp; factory.addConnectorCustomizers((TomcatConnectorCustomizer) connector -> {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; connector.setAttribute("relaxedPathChars", "<>[\\]^`{|}");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; connector.setAttribute("relaxedQueryChars", "<>[\\]^`{|}");&nbsp; &nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; }}
随时随地看视频慕课网APP

相关分类

Java
我要回答