Java 基于React的应用程序与spring引导捆绑在一起,作为WAR部署在websphere中
我正在尝试开发一个基于react的前端应用程序,将springboot作为后端。我正试图创建一场前端和后端在战争中耦合在一起的战争。然后我尝试将其部署到websphere。创建WAR并将其部署到websphere服务器后,当我尝试访问该页面时,它无法访问css页面nad,从而出现404 not found错误。react项目只是使用create react app命令创建的框架项目。它还没有任何有意义的代码。我提供pom文件供您参考。请帮助我,如果需要,我将提供任何其他代码Java 基于React的应用程序与spring引导捆绑在一起,作为WAR部署在websphere中,java,reactjs,maven,spring-boot,websphere,Java,Reactjs,Maven,Spring Boot,Websphere,我正在尝试开发一个基于react的前端应用程序,将springboot作为后端。我正试图创建一场前端和后端在战争中耦合在一起的战争。然后我尝试将其部署到websphere。创建WAR并将其部署到websphere服务器后,当我尝试访问该页面时,它无法访问css页面nad,从而出现404 not found错误。react项目只是使用create react app命令创建的框架项目。它还没有任何有意义的代码。我提供pom文件供您参考。请帮助我,如果需要,我将提供任何其他代码 <proper
<properties>
<java.version>1.8</java.version>
<frontend-maven-plugin.version>1.6</frontend-maven-plugin.version>
<node.version>v12.13.0</node.version>
<npm.version>6.12.0</npm.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope> <optional>true</optional> </dependency> <dependency>
<groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope> </dependency> -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<!-- <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> -->
<build>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<phase>process-classes</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/classes/resources</outputDirectory>
<resources>
<resource>
<directory>${basedir}/src/main/webapp/XXX/build</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>${frontend-maven-plugin.version}</version>
<configuration>
<workingDirectory>src/main/webapp/XXX</workingDirectory>
</configuration>
<executions>
<execution>
<id>Install node and npm locally to the project</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<!-- optional: default phase is "generate-resources" -->
<phase>generate-resources</phase>
<configuration>
<nodeVersion>${node.version}</nodeVersion>
<npmVersion>${npm.version}</npmVersion>
</configuration>
</execution>
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
<phase>generate-resources</phase>
</execution>
<execution>
<id>Build frontend</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>run build</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
我得到以下错误:
加载资源失败:服务器响应的状态为404 Not Found main.c17080f1.css:1如果WAR的上下文根不是/,则需要配置React应用程序生成器,将该上下文根包含在其引用的所有资源的url中。将指导您设置基础URL以供React使用。如果WAR的上下文根不是/,则您需要配置React应用程序生成器,以将该上下文根包含在其引用的所有资源的URL中。将指导您设置基本URL以供React使用。谢谢您的帮助。教程帮助我解决了这个问题。谢谢你的帮助。教程帮助我解决了这个问题。
React package.json:
{
"name": "next-gen-ui",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.11.0",
"react-dom": "^16.11.0",
"react-scripts": "1.1.5"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}