spring boot 2.7 集成JSP

2023-05-21  本文已影响0人  旧日回忆

配置 <packaging>war</packaging>, 一定要是war, 并且不能修改后缀".war"
linux也会引用locale导致不将中文名称的文件打包进去

增加依赖

<dependency>
    <groupId>org.apache.tomcat.embed</groupId>
    <artifactId>tomcat-embed-jasper</artifactId>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
</dependency>
spring:
  mvc:
    view:
      prefix: /WEB-INF/views/
      suffix: .jsp

目录结构

main
    - java
    - resources
    - webapp
        - static
        - WEB-INF
          - views
              hello.jsp

-------------------idea启动----
需要working directory增加配置


image.png

------------加快第一次访问JSP页面---

public class EmbeddedTomcatConfiguration {

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

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

  @Bean
  public WebServerFactoryCustomizer<TomcatServletWebServerFactory> servletContainerCustomizer() {
    return new WebServerFactoryCustomizer<TomcatServletWebServerFactory>() {

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

猜你喜欢

热点阅读