0

我創建了一個Spring Boot應用程序,我想部署通過Yeoman(角度生成器)生成的Web前端。然而,我無法讓事情發揮作用:當我運行應用程序時,我的靜態資源被部署用於生產(localhost:8080/dist/index.html正在運行很酷),而不是用於開發(localhost:8080/app/index.html不工作很酷)。Spring Boot Maven Plugin和Grunt with live reload

我將整個web前端結構移動到static。通過終端,我可以cd到該文件夾​​(src/main/resources/static)並運行grunt buildgrunt serve;這樣,當我在前端工作時,我可以利用實時重新加載。

然後,我創建了下面的腳本在項目的根通過咕嚕建立我的前端:

echo 'Running grunt build...' 
cd src/main/resources/static 
grunt build 
echo 'Done running grunt' 

我修改pom.xml如下:

<build> 
<plugins> 
    <plugin> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-maven-plugin</artifactId> 
    </plugin> 

    <plugin> 
    <artifactId>exec-maven-plugin</artifactId> 
    <groupId>org.codehaus.mojo</groupId> 
    <executions> 
     <execution> 
     <id>Grunt build</id> 
     <phase>install</phase> 
     <goals> 
      <goal>exec</goal> 
     </goals> 
     <configuration> 
      <executable>${basedir}/runGrunt.sh</executable> 
     </configuration> 
     </execution> 
    </executions> 
    </plugin> 

</plugins> 
</build> 

現在,當我執行mvn spring-boot:run ,我的Spring項目開始正確,但是咕嚕聲是爲生產而建的(訪問app/index.html不會讓我加載角色& co)。

我怎樣才能連線的東西,這樣我可以執行mvn spring-boot:run拿到我的前端項目編制,部署和現場重裝(即我要訪問本地主機:8080 /應用/ index.html,然後拿到角&共同加載) ?

回答

0

作爲一個部分解決方案,我選擇在端口9000上運行一個新服務器(默認),以在每次運行我的應用程序時提供文件。

兩件事情是必要的:(1)本替換EXEC-Maven的插件部分:

<plugin> 
    <artifactId>exec-maven-plugin</artifactId> 
    <groupId>org.codehaus.mojo</groupId> 
    <version>1.4.0</version> 
    <configuration> 
      <executable>${basedir}/runGrunt.sh</executable> 
    </configuration> 
</plugin> 

(2)執行Maven的目標EXEC:運行應用程序之前EXEC。

這樣,前端在端口8080上不可用,但它在9000上正常工作,無需手動運行命令即可提供服務。