Spring boot + jsp打成war包后第一次访问慢

尝试过的方案有:

1,servlet配置load-on-startup的作用–配置spring.mvc.servlet.load-on-startup=1
2,指定配置文件中spring.datasource.druid.initial-size=1,即启动时会初始化数据库连接
3,JDK优化之熵池策略–加启动参数 -Djava.security.egd=file:/dev/./urandom

以上方案均无效

最终有效的解决方案是增加如下配置:

@Configuration
public class EmbeddedTomcatConfiguration {

  @Bean
  TomcatServletWebServerFactory tomcatFactory() {
    return new TomcatServletWebServerFactory() {

      @Override
      protected void postProcessContext(Context context) {
        context.setResources(new ExtractingRoot());
      }
    };
  }

  @Bean
  public WebServerFactoryCustomizer servletContainerCustomizer() {
    return new WebServerFactoryCustomizer() {

      @Override
      public void customize(TomcatServletWebServerFactory container) {
        container.addContextCustomizers(
            new TomcatContextCustomizer() {
              @Override
              public void customize(Context cntxt) {
                cntxt.setReloadable(false);
              }
            });
      }
    };
  }
}

参考链接:

https://stackoverflow.com/questions/59242577/why-my-springboot-with-embbeded-tomcat-too-slow-when-process-first-request

 

 

 

 

你可能感兴趣的:(java相关)