我有一個在 tomcat 中運行的 spring boot rest API 服務。
我有一個在節點 js 服務器上運行的 NextJS UI 應用程式。
現在我希望我的 NextJs 應用程式由 tomcat 服務器提供服務。
為了讓我的 nextjs 應用程式由 Sp??ring Boot 靜態檔案夾提供服務,我需要執行哪些必要步驟?
uj5u.com熱心網友回復:
Springboot 有一個撰寫良好的示例,說明如何將 React 與 Spring-Data-Rest 以及用于編譯/構建前端的 mvn 插件一起使用。
我知道 ReactJs 不是 NextJS,但它可能會有所幫助,并且可以為您提供一個開始:
maven插件是:frontend-maven-plugin
<build>
<pluginManagement>
<plugins>
<!-- tag::frontend-maven-plugin[] -->
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.9.1</version>
<configuration>
<installDirectory>target</installDirectory>
</configuration>
<executions>
<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<configuration>
<nodeVersion>v12.14.0</nodeVersion>
<npmVersion>6.13.4</npmVersion>
</configuration>
</execution>
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
<execution>
<id>webpack build</id>
<goals>
<goal>webpack</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- end::frontend-maven-plugin[] -->
</plugins>
</pluginManagement>
</build>
https://spring.io/guides/tutorials/react-and-spring-data-rest/
uj5u.com熱心網友回復:
我找到了答案。
步驟-1:編輯package.json ->在腳本屬性中添加“export”:“next export”
Step - 2:上述步驟將建立一個名為“out”的檔案夾。復制out檔案夾的內容。將其粘貼到src -> main -> resources -> static 檔案夾中。
步驟-3:現在構建spring boot jar/war,然后運行它。它將提供靜態檔案夾中的內容。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/440147.html
