Skip to content

Instantly share code, notes, and snippets.

@peerax
Forked from andreldm/AprConfiguration.java
Created December 8, 2017 23:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peerax/009a24ffcb90763a69b8b537b3db24e6 to your computer and use it in GitHub Desktop.
Save peerax/009a24ffcb90763a69b8b537b3db24e6 to your computer and use it in GitHub Desktop.
APR on Spring Boot
import org.apache.catalina.LifecycleListener;
import org.apache.catalina.core.AprLifecycleListener;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* NOTE: You also need to install APR on your system, on Arch Linux the package is called `tomcat-native`.
*/
@Configuration
public class AprConfiguration {
@Value("${server.tomcat.apr.enabled:false}")
private boolean enabled;
@Bean
public EmbeddedServletContainerFactory servletContainer() {
TomcatEmbeddedServletContainerFactory container = new TomcatEmbeddedServletContainerFactory();
if (enabled) {
LifecycleListener arpLifecycle = new AprLifecycleListener();
container.setProtocol("org.apache.coyote.http11.Http11AprProtocol");
container.addContextLifecycleListeners(arpLifecycle);
}
return container;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment