@Bean
public TomcatServletWebServerFactory servletContainerFactoryProd() {
TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() {
@Override
protected TomcatWebServer getTomcatWebServer(Tomcat tomcat) {
// to create new directories and files and add them to Context
return super.getTomcatWebServer(tomcat);
}
};
Connector connector = new Connector("org.apache.coyote.http11.Http11AprProtocol");
Http11AprProtocol protocol = (Http11AprProtocol) connector.getProtocolHandler();
connector.setProperty("compression", "on");
connector.setProperty("compressableMimeType", "text/html,text/xml,text/plain,application/json,application/xml");
// can also enable ssl and provide certificate details
tomcat.addAdditionalTomcatConnectors(connector);
return tomcat;
}
1条答案
按热度按时间wbrvyc0a1#
我们可以在嵌入了springboot的tomcat中启用APR,方法是覆盖org.springframework.boot.web.embedded. tomcat.tomcatServletWebServerFactory,并提供新的 Catalina .connector.连接器和org.apache.coyote.http11.Http11AprProtocol协议。
下面的代码可能有助于完成它。