I am creating a RESTApi using spring framework. My IDE is STS. Embedded Tomcat concept is pretty useful and easy to implement. Just export a jar, run it and boom your service is up and running, but embedded Tomcat is using Nio HTTP Connector. I did some research and find out that APR HTTP Connector is much more better than Nio and I want to use APR. Still there is an option : export a war file, deploy it into a tomcat and configure its HTTP connector. But I really like embedded tomcat and I am wondering is it possible to change its HTTP Connector from Nio to APR ?
Asked
Active
Viewed 4,107 times
1
-
Depending if you use SpringBoot, see this discussions, maybe usefull to you: [Use Tomcat APR connector for performance improvements](https://github.com/spring-projects/spring-boot/issues/7376), [HTTP/2 and modern TLS support](https://github.com/spring-projects/spring-boot/issues/10043), [Use AprLifecycleListener with embedded Tomcat by default](https://github.com/spring-projects/spring-boot/pull/10079#issuecomment-326970302) and this answer on stackoverflow: https://stackoverflow.com/questions/40319869/spring-boot-embedded-tomcat-performance#comment71137077_40446766 – Okoch Feb 01 '18 at 12:27
-
Hi. Did you manage to implement apr with embedded tomcat? Also did you implement HTTP/2 in embedded tomcat. – sam Dec 05 '18 at 06:22
1 Answers
0
We can enable APR in springboot embeded tomcat by overiding the org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory and providing new org.apache.catalina.connector.Connector with org.apache.coyote.http11.Http11AprProtocol protocol.
The below code might help to get it done.
@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;
}

Mukulit Bhati
- 11
- 1
- 6