Spring应用程序在从Eclipse运行时通常在嵌入式Tomcat服务器上运行,但当我将它部署到外部tomcat服务器(在Windows上)时,我得到了HTTP 404状态。
我清理了包,复制了目标文件夹war文件,在本地tomcat服务器上的tomcat webapp文件夹中,我重新启动tomcat,但是.
当我在带有端点http://localhost:8080/export/test/的postman中运行get方法时,没有找到404
Tomcat版本9
Java 11
TOMCAT管理器:

@SpringBootApplication
public class ExportApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(ExportApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(ExportApplication.class);
}
}POM文件:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>bojankosta</groupId>
<artifactId>export</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>export</name>
<description>Export db</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>${artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>application.properties:
server.servlet.context-path=/export控制器:
package bojankosta.export.controller;
import bojankosta.export.service.ContinentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class BasicController {
@Autowired
private ContinentService continentService;
@GetMapping("/")
public String getAllData() {
return continentService.export();
}
@GetMapping("/test")
@ResponseBody
public String currentUserName() {
return "Hello";
}
}发布于 2022-01-10 10:07:12
404意味着您所访问的url不是available.When --我们将代码部署在外部应用程序服务器上,它是从通常以项目名称开始的根上下文中提供的。您可以在日志中签入它所服务的上下文,然后附加它的.It将工作的其他端点。
发布于 2022-01-10 10:46:33
可以在构建文件中使用finalName属性(pom.xml用于maven)
<finalName>export</finalName>https://stackoverflow.com/questions/70650616
复制相似问题