Spring打包jar包时jsp页面无法访问问题解决

spring打包jar包时jsp页面无法访问

问题如下

Spring打包jar包时jsp页面无法访问问题解决_第1张图片

当前pom.xml配置


    
      
      
        src/main/resources
        false
      
      
      
        src/main/webapp
        META-INF/resources
        false
      
    

    
      
        org.springframework.boot
        spring-boot-maven-plugin
        
      
       
        org.apache.maven.plugins 
        maven-surefire-plugin 
         
          true 
         
      
    
  

解决办法:

1.高版本的插件不支持jsp,给spring-boot-maven-plugin指定版本号“1.4.2.RELEASE”


    
      
      
        src/main/resources
        false
      
      
      
        src/main/webapp
        META-INF/resources
        false
      
    

    
      
        org.springframework.boot
        spring-boot-maven-plugin
        1.4.2.RELEASE
      
       
        org.apache.maven.plugins 
        maven-surefire-plugin 
         
          true 
         
      
    
  

2.根据spring官网说明,可打包war包,仍然可使用jar -jar xxx.war执行。

https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-jsp-limitations

JSP Limitations
When running a Spring Boot application that uses an embedded servlet container (and is packaged as an executable archive), there are some limitations in the JSP support.

With Jetty and Tomcat, it should work if you use war packaging. An executable war will work when launched with java -jar, and will also be deployable to any standard container. JSPs are not supported when using an executable jar.

Undertow does not support JSPs.

Creating a custom error.jsp page does not override the default view for error handling. Custom error pages should be used instead.

war

https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-documentation

spring官方不推荐使用jsp,推荐使用thymeleaf、freemaker、velocity等其他模块引擎。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

你可能感兴趣的:(Spring打包jar包时jsp页面无法访问问题解决)