Commit 51315918 authored by Gradl, Tobias's avatar Gradl, Tobias
Browse files

418: Improve performance of deployed WAR container (OPENED)

Task-Url: #418
parent f362efe7
package eu.dariah.de.search.config;
import org.apache.catalina.Context;
import org.apache.catalina.webresources.ExtractingRoot;
import org.apache.tomcat.util.scan.StandardJarScanner;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
......@@ -28,21 +28,22 @@ public class ApplicationConfig {
public void setContextPath(String contextPath) { this.contextPath = contextPath; }
/**
* WebServerFactoryCustomizer bean that adapts to a configured context path for the application. This adaption is not
* necessary for implementation of the dariahsp-core library, but helps with setting up the application as it might
* be available or proxied at their deployments
* WebServerFactoryCustomizer bean that adapts to a configured context path for the application.
* This adaption helps with setting up the application as it might be available or proxied at their deployments
*
* @return WebServerFactoryCustomizer
*/
@Bean
public WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> webServerFactoryCustomizer() {
public WebServerFactoryCustomizer<TomcatServletWebServerFactory> servletContainerCustomizer() {
log.info("Web server context path set to {}", contextPath.isEmpty() ? "/" : contextPath);
return factory -> factory.setContextPath(contextPath);
return container -> container.addContextCustomizers(context -> {
context.setReloadable(false);
context.setPath(contextPath);
});
}
/**
* Provides tomcat factory bean disabling TLD scanning:
* @see https://stackoverflow.com/a/52229296
* Provides tomcat factory
*
* @return TomcatServletWebServerFactory tomcatFactory
*/
......@@ -51,6 +52,11 @@ public class ApplicationConfig {
return new TomcatServletWebServerFactory() {
@Override
protected void postProcessContext(Context context) {
// extracting packaged war file for better performance:
// @see https://stackoverflow.com/a/62759292
context.setResources(new ExtractingRoot());
// disabling TLD scanning:
// @see https://stackoverflow.com/a/52229296
((StandardJarScanner) context.getJarScanner()).setScanManifest(false);
}
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment