在 Tomcat api 中部署 war 文件后无法正常工作
After deploying war file in Tomcat api not working
我正在尝试在本地 tomcat 中部署应用程序,但遇到了一些问题。我使用:Tomcat9,Springboot,ReactJS 和 Webpack。当我 运行 嵌入 Tomcat (在 Eclipse 中)时一切正常 - API 工作正常,但是当我构建 war 文件并将其粘贴到我的本地 Tomcat - API 不工作,所有请求都失败了。
我如何构建 war 文件:
- 运行 mvn "clean install";
- 粘贴war文件到我的本地Tomcat目录"webapps";
- 等待部署;
- 转到“http://localhost:8080/web_importer/#/importCandidates". But in this moment when i run in Eclipse my app i use another path: "http://localhost:8080/#/importCandidates" and API use this path to (example) "http://localhost:8080/api/originator", not "http://localhost:8080/web_importer/api/originator”。
如何更改此路径?
application.properties:
server.port = 8080
management.server.port: 8995
management.server.address: 127.0.0.1
spring.servlet.multipart.max-file-size=100MB
spring.servlet.multipart.max-request-size=100MB
spring.http.encoding.force=true
OriginatorController.java:
@RequestMapping(value = "/api/originator", method = RequestMethod.GET)
public List<OriginatorModel> retrieveOriginators() {
logger.info("Performing /api/originator GET request");
return originatorService.retrieveOriginators();
}
我的pom.xml:
<groupId>com.kddb_web_importer</groupId>
<artifactId>web_importer</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>web_importer</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
当您从 Eclipse 启动应用程序时,它使用独立服务器,可通过本地主机直接访问,URL 为 http://localhost:8080/api/originator。
当你 运行 你的本地 tomcat 实例时,http://localhost:8080 is the base tomcat URL. What follows next is the name of your application, in this case web_importer. So the URL becomes http://localhost:8080/web_importer/api/originator 这就是你得到 404 Not Found 的原因。
您的前端似乎直接在 http://localhost:8080/api/originator 调用 API。当您想使用 API.
的 tomcat 部署版本时,您需要在前端配置中更改基础 API URL
我正在尝试在本地 tomcat 中部署应用程序,但遇到了一些问题。我使用:Tomcat9,Springboot,ReactJS 和 Webpack。当我 运行 嵌入 Tomcat (在 Eclipse 中)时一切正常 - API 工作正常,但是当我构建 war 文件并将其粘贴到我的本地 Tomcat - API 不工作,所有请求都失败了。
我如何构建 war 文件:
- 运行 mvn "clean install";
- 粘贴war文件到我的本地Tomcat目录"webapps";
- 等待部署;
- 转到“http://localhost:8080/web_importer/#/importCandidates". But in this moment when i run in Eclipse my app i use another path: "http://localhost:8080/#/importCandidates" and API use this path to (example) "http://localhost:8080/api/originator", not "http://localhost:8080/web_importer/api/originator”。
如何更改此路径?
application.properties:
server.port = 8080
management.server.port: 8995
management.server.address: 127.0.0.1
spring.servlet.multipart.max-file-size=100MB
spring.servlet.multipart.max-request-size=100MB
spring.http.encoding.force=true
OriginatorController.java:
@RequestMapping(value = "/api/originator", method = RequestMethod.GET)
public List<OriginatorModel> retrieveOriginators() {
logger.info("Performing /api/originator GET request");
return originatorService.retrieveOriginators();
}
我的pom.xml:
<groupId>com.kddb_web_importer</groupId>
<artifactId>web_importer</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>web_importer</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
当您从 Eclipse 启动应用程序时,它使用独立服务器,可通过本地主机直接访问,URL 为 http://localhost:8080/api/originator。
当你 运行 你的本地 tomcat 实例时,http://localhost:8080 is the base tomcat URL. What follows next is the name of your application, in this case web_importer. So the URL becomes http://localhost:8080/web_importer/api/originator 这就是你得到 404 Not Found 的原因。
您的前端似乎直接在 http://localhost:8080/api/originator 调用 API。当您想使用 API.
的 tomcat 部署版本时,您需要在前端配置中更改基础 API URL