Java 弹簧靴和反应罐';t load index.html

Java 弹簧靴和反应罐';t load index.html,java,spring,reactjs,spring-mvc,Java,Spring,Reactjs,Spring Mvc,我试图使用createreact-app和Spring-Boot创建一个简单的web应用程序,但是Spring在参考资料中找不到index.html React的build文件夹被maven resources插件复制到target: <plugin> <artifactId>maven-resources-plugin</artifactId> ... <phase>package</p

我试图使用
createreact-app
和Spring-Boot创建一个简单的web应用程序,但是Spring在参考资料中找不到
index.html

React的
build
文件夹被
maven resources插件复制到
target

<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>
获取对本地主机的请求:8080
返回
404
。你能告诉我哪里错了吗

更新:

@Controller
public class BasicController {
   @RequestMapping(value = "/", method = RequestMethod.GET)
   public String index() {
      return "index";
   }
}
通过将maven插件中React的buildoutput目录更改为
${basedir}/src/main/resources/META-INF/resources

返回“index”
返回index.html

好吧,这可能不是你问题的准确答案,但我会试试这个例子

Spring Boot将自动添加位于以下任何目录中的静态web资源:

/META-INF/资源/

/资源/

/静止的/

/公开的/

在使用jQuery指南使用RESTful Web服务的情况下,我们在/public/文件夹中包含index.html和hello.js文件。这意味着SpringBoot不仅提供了构建Java或Groovy应用程序的简单方法,还可以使用它轻松部署客户端JavaScript代码,并在真实的web服务器环境中进行测试

只需将CRA构建目录的内容复制到Spring Boot
public
目录(确保index.html位于
/public/index.html


如果这样做有效,那么尝试自动化这个过程。

我也有同样的问题。带有reactjs前端的Spring引导后端。我通过添加一个视图解析器(thymeleaf)并将生成的react构建资源复制到
outputDirectory/templates
目录来解决这个问题,如下所示

<plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>generate-resources</phase>
                        <configuration>
                            <target>
                                <copy todir="${project.build.outputDirectory}/templates">
                                    <fileset
                                        dir="${project.basedir}/src/main/javascript/build" />
                                </copy>
                            </target>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

maven antrun插件
产生资源
跑

我将index.html保存在静态目录中,但在集成我的react应用程序时只是将“.html”添加到索引中,就像这样:@RequestMapping(value=“/”)public String index(){return“index.html”;}。我仍然不知道为什么仅仅“索引”是不够的。我看到的大多数例子都说“索引”。也许是因为我没有设置webMvc?我有一个纯粹安静的后端。