jor*_*gos 2 spring reactjs spring-boot webpack
我想从 Spring Boot 服务器应用程序提供 ReactJS UI 应用程序的 Webpack 构建结果。
由于 Webpack 构建在“dist”文件夹中生成所有资产,即 index.html、bundle.js 等...访问为即http://localhost/index.html
Spring Boot 应用程序提供来自 ie http://localhost/api/xxx的 API URL
.env在 react 项目的根目录中创建文件(在 package.json 旁边)PUBLIC_URL=/nameContextRoot于.env文件(上下文根目录的名称通常是战争的文件名)npm run build对我来说,它在build反应项目的目录中生成它的内容
static目录下static 目录应该是一个普通文件夹 src/main/resources
清理并重建 spring boot 项目并运行它
内容现在可以正常提供
更新
Spring Boot 结构
D:.
????.mvn
? ????wrapper
????.settings
????src
? ????main
? ? ????java
? ? ? ????my.java.stuff
? ? ????resources
? ? ? ????static
? ? ? ????static
? ? ? ????css
? ? ? ????js
? ? ????webapp
? ????test
? ????java
? ????my.java.tests
????target
? ????classes
? ? ????java.classes
? ? ????static
? ? ????css
? ? ????js
? ? ????static
? ? ????css
? ? ????js
? ????generated-sources
? ? ????annotations
? ????m2e-wtp
? ? ????web-resources
? ? ????META-INF
? ? ????maven
? ? ????java.stuff
? ????maven-archiver
? ????maven-status
? ? ????maven-compiler-plugin
? ? ????compile
? ? ????default-compile
? ????rclient-0.0.1-SNAPSHOT
? ? ????META-INF
? ? ????WEB-INF
? ? ????classes
? ? ? ????java stuff
? ? ? ????static
? ? ????lib
? ????test-classes
????WebContent
????META-INF
Run Code Online (Sandbox Code Playgroud)
ReactJS 项目结构
D:.
????build
? ????static
? ????css
? ????js
????node_modules
????public
????src
????components
????domain
????util
Run Code Online (Sandbox Code Playgroud)
您的 api 端点也将在上下文根下提供。它们与 React 无关。
@Codo 使用反向代理访问静态内容的提示仍然有效。但是在这里您专门询问了如何在 Spring Boot 应用程序中托管 React 应用程序。
| 归档时间: |
|
| 查看次数: |
3143 次 |
| 最近记录: |