diff --git a/libresonic-main/src/main/java/org/libresonic/player/boot/Application.java b/libresonic-main/src/main/java/org/libresonic/player/boot/Application.java index 8d1fa8eb..2c1493c7 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/boot/Application.java +++ b/libresonic-main/src/main/java/org/libresonic/player/boot/Application.java @@ -1,6 +1,9 @@ package org.libresonic.player.boot; import net.sf.ehcache.constructs.web.ShutdownListener; +import org.apache.catalina.Container; +import org.apache.catalina.Wrapper; +import org.apache.catalina.webresources.StandardRoot; import org.directwebremoting.servlet.DwrServlet; import org.libresonic.player.filter.*; import org.libresonic.player.spring.LibresonicPropertySourceConfigurer; @@ -11,6 +14,10 @@ import org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration; import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer; +import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer; +import org.springframework.boot.context.embedded.tomcat.TomcatContextCustomizer; +import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.boot.web.support.SpringBootServletInitializer; @@ -32,7 +39,7 @@ import javax.servlet.ServletContextListener; "classpath:/applicationContext-cache.xml", "classpath:/applicationContext-sonos.xml", "classpath:/libresonic-servlet.xml"}) -public class Application extends SpringBootServletInitializer { +public class Application extends SpringBootServletInitializer implements EmbeddedServletContainerCustomizer { /** * Registers the DWR servlet. @@ -163,9 +170,36 @@ public class Application extends SpringBootServletInitializer { return doConfigure(application); } + @Override + public void customize(ConfigurableEmbeddedServletContainer container) { + if (container instanceof TomcatEmbeddedServletContainerFactory) { + TomcatEmbeddedServletContainerFactory tomcatFactory = (TomcatEmbeddedServletContainerFactory) container; + tomcatFactory.addContextCustomizers((TomcatContextCustomizer) context -> { + + // Increase the size and time before eviction of the Tomcat + // cache so that resources aren't uncompressed too often. + // See https://github.com/jhipster/generator-jhipster/issues/3995 + StandardRoot resources = new StandardRoot(); + resources.setCacheMaxSize(100000); + resources.setCacheObjectMaxSize(4000); + resources.setCacheTtl(24 * 3600 * 1000); // 1 day, in milliseconds + context.setResources(resources); + + // Put Jasper in production mode so that JSP aren't recompiled + // on each request. + // See http://stackoverflow.com/questions/29653326/spring-boot-application-slow-because-of-jsp-compilation + Container jsp = context.findChild("jsp"); + if (jsp instanceof Wrapper) { + ((Wrapper)jsp).addInitParameter("development", "false"); + } + }); + } + + } + public static void main(String[] args) { SpringApplicationBuilder builder = new SpringApplicationBuilder(); doConfigure(builder).run(args); } -} \ No newline at end of file +}