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

前段時間研究springboothtml

發現使用Application類啓動的話, 能夠進入Controller方法而且返回數據,可是不能跳轉到WEB-INF目錄下網頁,前端

前置配置java

 

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 啓動

會致使問題:web

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

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

解決方案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>springboot

 

進行webapp目錄配置後,  mvc

使用啓動類啓動  和 打包成jar包  均可以正常訪問了app

O(∩_∩)O哈哈~webapp

修改了配置 記得 clean 一下哦

原文地址 https://blog.csdn.net/q18771811872/article/details/88051260
相關文章
相關標籤/搜索