我正在尝试使用create-react-app
和Spring Boot 创建一个简单的Web应用程序,但是spring index.html
在资源中找不到。
反应过来的build
文件夹复制到target
由maven-resources-plugin
:
<plugin>
<artifactId>maven-resources-plugin</artifactId>
...
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
...
<outputDirectory>${basedir}/target/classes</outputDirectory>
<resources>
<resource>
<directory>src/main/app/build</directory>
<filtering>true</filtering>
</resource>
</resources>
...
</plugin>
这是我的项目结构:
控制器:
@Controller
public class BasicController {
@RequestMapping(value = "/", method = RequestMethod.GET)
public String index() {
return "index";
}
}
GET请求localhost:8080
返回404
。您能指出我在哪里吗?
更新:
通过将Maven插件中React的build输出目录更改为${basedir}/src/main/resources/META-INF/resources
和return "index"
来使其工作return index.html
。
好吧,这可能不是您问题的精确答案,但是我会尝试从docs中进行示例。
Spring Boot将自动添加位于以下任何目录中的静态Web资源:
/ META-INF /资源/
/资源/
/静态的/
/上市/
对于使用带有jQuery的RESTful Web服务进行使用的指南,我们在/ public /文件夹中包含了index.html和hello.js文件。这意味着Spring Boot不仅提供了一种构建Java或Groovy应用程序的简单方法,还可以使用它轻松地部署客户端JavaScript代码并在真实的Web服务器环境中对其进行测试!
只需将CRA构建目录的内容复制到Spring Boot public
目录(确保index.html位于/public/index.html
)。
如果可行,请尝试使该过程自动化。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句