springboot 啟動類啟動跳轉到前端網頁404問題的兩個解決方案


前段時間研究springboot

發現使用Application類啟動的話, 可以進入Controller方法並且返回數據,但是不能跳轉到WEB-INF目錄下網頁,

前置配置

 

server:
  port: 8086
  tomcat:
    uri-encoding: UTF-8
  servlet:
    context-path: /
spring:
  mvc:
    view:
      suffix: .jsp
      prefix: /WEB-INF/views/
  view:
    suffix: .jsp
    prefix: /WEB-INF/views/

 

 

使用啟動類或者啟動后。jar 404錯誤

控制台可以看見已經進入方法了  

解決方案1: 使用spring-boot:run 啟動

會導致問題:

打包成jar包  使用java -jar springboot.jar, 訪問前端 一樣會404

  缺陷彌補方案  ,打包成 war包,  使用java -jar springboot.war   就OK了 

解決方案2:配置pom.xml ,請看紅色字體,

    <resources>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.properties</include>
                <include>**/*.xml</include>
                <include>**/*.yml</include>
            </includes>
            <filtering>false</filtering>
        </resource>
        <resource>
            <directory>src/main/resources</directory>
            <includes>
                <include>**/*.properties</include>
                <include>**/*.xml</include>
                <include>**/*.yml</include>
                <include>**/*.txt</include>
            </includes>
            <filtering>false</filtering>
        </resource>
        <resource>
            <directory>src/main/webapp</directory>
            <targetPath>META-INF/resources</targetPath>
            <includes>
                <include>**/**</include>
            </includes>
        </resource>
    </resources>
</build>

<resource>
            <directory>src/main/webapp</directory>
            <targetPath>META-INF/resources</targetPath>
            <includes>
                <include>**/**</include>
            </includes>
</resource>

 

進行webapp目錄配置后,  

使用啟動類啟動  和 打包成jar包  都可以正常訪問了

O(∩_∩)O哈哈~

修改了配置 記得 clean 一下哦

原文地址 https://blog.csdn.net/q18771811872/article/details/88051260
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM