springboot项目访问jsp页面报404

<modelVersion>4.0.0</modelVersion>
 
    <groupId>com.项目名</groupId>
    <artifactId>statisticalvisits</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    <!--<packaging>war</packaging> 如果需要打包在tomcat中运行 可替换为war包,mvn打包会根据此处来执行 -->
 
    <name>statisticalvisits</name>
    <description>Demo project for Spring Boot</description>
 
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
<!-- 此处网上有很多博客说如果使用jsp页面,就必须使用springboot-1.4.2版本,但是我使用的时候用的2.0.6没有问题,反而用1.4.x会出问题,如果你有问题可以考虑换位1.4.2的试试 -->
 
        <!--<version>1.4.2.RELEASE</version> -->
        <version>2.0.6.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
 
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>
 
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>1.3.1</version>
        </dependency>
 
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
 
<!-- mysql jar包依赖 -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
 
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-freemarker</artifactId>
        </dependency>
 
        <dependency>
            <groupId>c3p0</groupId>
            <artifactId>c3p0</artifactId>
            <version>0.9.1.1</version>
        </dependency>
 
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
        </dependency>
 
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </dependency>
<!-- 使用jsp页面模板,必须有这个依赖 ,版本号可自行在mvn仓库选择-->
 
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <version>8.5.34</version>
        </dependency>
    </dependencies>
 
    <build>
<!-- 如果使用打war包,包名可根据此处更改为你想要的项目名,不然放到tomcat运行后项目名可能不是这个 -->
 
<!--<finalName>visitCount</finalName>-->
        <plugins>
            <plugin>
<!-- maven插件 -->
 
                <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-resources-plugin</artifactId>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <useDefaultDelimiters>true</useDefaultDelimiters>
                </configuration>
            </plugin>
 
        </plugins>
 
        <resources>
<!-- 此处最为重要-否则打包后没有你的JSP页面模板,一定要记得写为资源文件 targetPath 设置必须是 META-INF/resources 
 
我项目做出来的时候因为没写resources导致打包运行后正常启动,各个接口也都正常访问,但是所有的jsp页面都会报404,找不到页面 ,因为这个问题浪费了我大半天时间-->
 
            <resource>
                <directory>src/main/webapp</directory>
                <targetPath>META-INF/resources</targetPath>
                <includes>
                    <include>**/**</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
        <testResources>
            <testResource>
                <directory>src/test/resource</directory>
                <filtering>true</filtering>
            </testResource>
        </testResources>
    </build>


pom中<build>一定要记得写为资源文件 <targetPath> 设置必须是 META-INF/resources  否则打包后你的JSP页面模板在项目中的位置不对,springboot就无法定位到你的页面,我项目做出来的时候因为没写resources导致打包运行后正常启动,各个接口也都正常访问,但是所有的jsp页面都会报404,找不到页面 

然后jsp页面对应的springmvc的模板前缀后缀
spring.mvc.view.prefix=/
spring.mvc.view.suffix=.jsp

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值