springboot整合前端靜態資源及VUE項目,打包成jar

由於springboot內置了tomcat等容器,因此可以將前端程序打成jar包,減少多安裝tomcat工作,springboot整合前端靜態資源及VUE項目主要步驟如下:

一、pom build增加路徑映射配置

<build>
   <resources>
      <resource>
         <directory>${basedir}/src/main/webapp</directory>
         <!--注意此次必須要放在此目錄下才能被訪問到-->
         <targetPath>META-INF/resources</targetPath>
         <includes>
            <include>**/**</include>
         </includes>
      </resource>
      <resource>
         <directory>${basedir}/src/main/resources</directory>
         <includes>
            <include>**/**</include>
         </includes>
      </resource>
   </resources>
   <plugins>
      <plugin>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
   </plugins>
</build>

 

二、properties配置文件

spring boot項目中的靜態資源文件存放在static文件下面,當通過瀏覽器訪問這些靜態文件時,必須要添加static作爲前綴才能訪問,配置spring.mvc.static-path-pattern=/**,可不加static。

三、copy靜態資源到resources.static下,如下圖

四、springboot整合VUE

將打包好的vue程序放到static下,和上面三個步驟一致,將index.html放到templates資源文件夾下,如下圖:

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章