當我從 Eclipse 運行 Spring Boot 應用程式時,它在嵌入式 Tomcat 服務器上正常運行,但是當我將它部署到外部 tomcat 服務器(在 Windows 上)時,我得到 HTTP 404 狀態。
我做了清理包并從本地tomcat服務器上的tomcat webapps檔案夾中的目標檔案夾war檔案復制,我重新啟動了tomcat但是......
當我使用端點 http://localhost:8080/export/test/ 在郵遞員中運行 get 方法時,我得到 404 not found
Tomcat 版本 9
Java 11
湯姆貓經理:

@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>
應用程式屬性:
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";
}
}
uj5u.com熱心網友回復:
404 表示您點擊的 url 不可用。當我們在外部應用程式服務器上部署代碼時,它從通常以專案名稱開頭的根背景關系提供服務。您可以在日志中檢查它所服務的背景關系是什么,然后附加其余端點。它會起作用
uj5u.com熱心網友回復:
您可以在構建檔案中使用 finalName 屬性(maven 的 pom.xml)
<finalName>export</finalName>
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/408184.html
標籤:
上一篇:發布資料時為空
