美文网首页
spring boot 2.7 集成JSP

spring boot 2.7 集成JSP

作者: 旧日回忆 | 来源:发表于2023-05-21 20:09 被阅读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);
                  }
                });
          }
        };
      }
    }
    

    相关文章

      网友评论

          本文标题:spring boot 2.7 集成JSP

          本文链接:https://www.haomeiwen.com/subject/hircldtx.html