[英]HTTP Status 404 after deploying a web application with a custom realm to Tomcat 6
[英]SOLVED - HTTP Status 404 for Spring Web REST API after deploying dynamic application to Tomcat server on Eclipse
我有一个新的 Spring Web 应用程序来自https://start.Z2A2D595E6ED9ED9A0B24F027 。 每当我尝试访问 REST controller 路径(“api/companies”)时,服务器都会发送带有以下消息的 404 结果:
“源服务器没有找到目标资源的当前表示或不愿意透露存在的表示。”。
这是我的 pom.xml:
<?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.2.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>helium.erp.com</groupId>
<artifactId>companies</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>companies</name>
<description>Demo project for Spring Boot</description>
<packaging>jar</packaging>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</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>
</exclusions>
</dependency>
<dependency>
<groupId>com.oracle.ojdbc</groupId>
<artifactId>ojdbc8</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
这是项目结构的样子:
应用程序的入口点是 CompaniesApplication class:
package helium.erp.com.companies;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
@SpringBootApplication
public class CompaniesApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(CompaniesApplication.class, args);
}
}
我试图达到的 REST controller 如下:
package helium.erp.com.companies.company;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/api/companies")
public class CompanyApi {
@GetMapping(value = "")
public ResponseEntity<String> getAllCompanies() {
return ResponseEntity.ok("all companies");
}
}
我在 WebContent 的根目录中放置了一个 html 文件,当我向“localhost:9091”发送 GET 时完美返回。 该项目被添加为服务器资源,这里是服务器的配置:
我已通过 Eclipse 项目设置 > web 项目设置 > 上下文根将项目上下文根从默认的“公司”更改为“/”,并通过服务器模块设置更改路径,如下所示:
我究竟做错了什么? 我缺少一些配置吗?
[已解决] 修复 Eclipse 中的部署程序集路径解决了该问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.