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

 更新时间:2020年05月15日 11:50:36   作者:pcant  
这篇文章主要介绍了Spring打包jar包时jsp页面无法访问问题解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

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

问题如下

当前pom.xml配置

<build>
    <resources>
      <!--引入配置文件-->
      <resource>
        <directory>src/main/resources</directory>
        <filtering>false</filtering>
      </resource>
      <!--引入静态文件-->
      <resource>
        <directory>src/main/webapp</directory>
        <targetPath>META-INF/resources</targetPath>
        <filtering>false</filtering>
      </resource>
    </resources>

    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        
      </plugin>
      <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-surefire-plugin</artifactId> 
        <configuration> 
          <skipTests>true</skipTests> 
        </configuration> 
      </plugin>
    </plugins>
  </build>

解决办法:

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

<build>
    <resources>
      <!--引入配置文件-->
      <resource>
        <directory>src/main/resources</directory>
        <filtering>false</filtering>
      </resource>
      <!--引入静态文件-->
      <resource>
        <directory>src/main/webapp</directory>
        <targetPath>META-INF/resources</targetPath>
        <filtering>false</filtering>
      </resource>
    </resources>

    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <version>1.4.2.RELEASE</version>
      </plugin>
      <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-surefire-plugin</artifactId> 
        <configuration> 
          <skipTests>true</skipTests> 
        </configuration> 
      </plugin>
    </plugins>
  </build>

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.

<packaging>war</packaging>

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

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

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

相关文章

  • 关于WeakhashMap与HashMap之间的区别和联系

    关于WeakhashMap与HashMap之间的区别和联系

    这篇文章主要介绍了关于WeakhashMap与HashMap之间的区别和联系,WeakHashMap从名字可以得知主要和Map有关,不过还有一个Weak,我们就更能自然而然的想到这里面还牵扯到一种弱引用结构,因此想要彻底搞懂,我们还需要知道四种引用,需要的朋友可以参考下
    2023-09-09
  • spring boot与kafka集成的简单实例

    spring boot与kafka集成的简单实例

    本篇文章主要介绍了spring boot与kafka集成的简单实例,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-09-09
  • IDEA实用好用插件推荐及使用方法教程详解(必看)

    IDEA实用好用插件推荐及使用方法教程详解(必看)

    这篇文章主要介绍了IDEA实用好用插件推荐及使用方法教程,本文通过实例截图相结合给大家介绍的非常详细,对大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2020-04-04
  • Java中守护线程介绍及使用

    Java中守护线程介绍及使用

    大家好,本篇文章主要讲的是Java中守护线程介绍及使用,感兴趣的同学赶快来看一看吧,对你有帮助的话记得收藏一下
    2022-01-01
  • spring NamedContextFactory在Fegin配置及使用详解

    spring NamedContextFactory在Fegin配置及使用详解

    在我们日常项目中,使用FeignClient实现各系统接口调用变得更加简单, 在各个系统集成过程中,难免会遇到某些系统的Client需要特殊的配置、返回读取等需求。Feign使用NamedContextFactory来为每个Client模块构造单独的上下文(ApplicationContext)
    2023-11-11
  • SpringBoot集成MyBatis的多种方式

    SpringBoot集成MyBatis的多种方式

    本文深入解析了Spring Boot集成MyBatis的多种方式,包括XML配置、注解配置以及MyBatis的动态SQL等,具有一定的参考价值,感兴趣的可以了解一下
    2023-12-12
  • 根据list中对象的属性去重和排序小结(必看篇)

    根据list中对象的属性去重和排序小结(必看篇)

    下面小编就为大家带来一篇根据list中对象的属性去重和排序小结(必看篇)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-05-05
  • 配置pom.xml用maven打包java工程的方法(推荐)

    配置pom.xml用maven打包java工程的方法(推荐)

    下面小编就为大家带来一篇配置pom.xml用maven打包java工程的方法(推荐)。小编觉得挺不错的, 现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2016-06-06
  • Spring Boot webflux使用方法解析

    Spring Boot webflux使用方法解析

    这篇文章主要介绍了Spring Boot webflux使用方法解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
    2020-03-03
  • SpringBoot应用自定义logback日志详解

    SpringBoot应用自定义logback日志详解

    默认情况下,SpringBoot内部使用logback作为系统日志实现的框架,将日志输出到控制台,不会写到日志文件。本篇文章主要讲解下如何自定义logabck.xml以及对logback文件中配置做一个详解,需要的可以参考一下
    2022-10-10

最新评论