Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 我可以在one spring项目中创建两个react应用程序吗?_Reactjs_Spring Boot_Spring Mvc - Fatal编程技术网

Reactjs 我可以在one spring项目中创建两个react应用程序吗?

Reactjs 我可以在one spring项目中创建两个react应用程序吗?,reactjs,spring-boot,spring-mvc,Reactjs,Spring Boot,Spring Mvc,我有两个web应用程序的不同部分,即公共站点和管理站点。我想为它们创建不同的独立react应用程序。对于API,我使用SpringBoot。 我能在我的情况下这样做吗? 我需要向webpack.config.js文件添加什么 我试图再创建一个HTML页面并呈现给那个应用程序。但这是行不通的。因为一个react应用程序只渲染一次 我希望使用一个API运行两个不同的react应用程序。有两个主要选项: 将3个应用程序(spring boot、react public、react admin)拆分为

我有两个web应用程序的不同部分,即公共站点和管理站点。我想为它们创建不同的独立react应用程序。对于API,我使用SpringBoot。 我能在我的情况下这样做吗? 我需要向webpack.config.js文件添加什么

我试图再创建一个HTML页面并呈现给那个应用程序。但这是行不通的。因为一个react应用程序只渲染一次


我希望使用一个API运行两个不同的react应用程序。

有两个主要选项:

  • 将3个应用程序(spring boot、react public、react admin)拆分为单独的存储库,并单独部署
  • 在Maven多模块构建中使用1个repo
我将根据你的问题假设你想做选项2

在这种情况下,创建如下结构:

+ project
| - backend-api
| - frontend-public
| - frontend-admin
父级
pom.xml
应参考3个模块:

<modules>
    <module>backend-api</module>
    <module>frontend-public</module>
    <module>frontend-admin</module>
</modules>

这将把react应用程序解压到
/static/public
/static/admin
。因此,Spring Boot将在您的应用程序中的
/public
/admin
为它们提供服务。

感谢您的帮助,我将开始按照您所写的方式重新构建我的项目。
<parent>
    <groupId>com.mycompany.myproject</groupId>
    <artifactId>myproject</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</parent>
<dependencyManagement>
    <dependencies>            
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>${spring.boot.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>
<plugin>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>unzip-webapp-public</id>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>unpack</goal>
                    </goals>
                    <configuration>
                        <artifactItems>
                            <artifactItem>
                                <groupId>com.mycompany.myproject</groupId>
                                <artifactId>frontend-public</artifactId>
                                <version>${project.parent.version}</version>
                                <classifier>distribution</classifier>
                                <type>zip</type>
                            </artifactItem>
                        </artifactItems>
                        <outputDirectory>${project.build.directory}/classes/static/public</outputDirectory>
                    </configuration>
                </execution>
                <execution>
                    <id>unzip-webapp-admin</id>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>unpack</goal>
                    </goals>
                    <configuration>
                        <artifactItems>
                            <artifactItem>
                                <groupId>com.mycompany.myproject</groupId>
                                <artifactId>frontend-admin</artifactId>
                                <version>${project.parent.version}</version>
                                <classifier>distribution</classifier>
                                <type>zip</type>
                            </artifactItem>
                        </artifactItems>
                        <outputDirectory>${project.build.directory}/classes/static/admin</outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>