Spring 启动应用程序在本地主机上运行,​​但 returns 404 在外部 Tomcat

Spring Boot application runs on localhost but returns 404 on external Tomcat

我创建了一个 Spring 引导应用程序,具有 Spring 安全性,以公开一些 REST API 端点。 我使用内置的 IntelliJ Ultimate Spring Initializr.

创建了项目

Spring版本:2.4.4
类型:Maven
Java版本:8
包装:War

当我从 IntelliJ 中 运行 应用程序并启动 Tomcat 9.0.44.
的实例时 然后,我使用 maven>package 创建了一个 WAR 文件,以在我的 PC 的本地 XAMPP 安装中进行测试。 (我使用 Tomcat 8.5.53。原因是这是我最终要部署到的生产环境中可用的 Tomcat 版本。 )
我使用 tomcat 管理器进行部署,运行 也没有任何问题。
然后我将 war 移动到我们的生产服务器并使用 Tomcat 管理器 UI 进行部署。
我可以在管理器中看到它已部署并且正在 运行ning.
生产服务器Tomcat管理员UI

当我尝试使用 Postman 访问我的端点时,无论我尝试访问哪个端点,我总是收到 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.4.4</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.apiauthentication</groupId>
    <artifactId>auth-server</artifactId>
    <version>1.0.0</version>
    <packaging>war</packaging>
    <name>FLEET_Authentication_Server</name>
    <description>Authentication Server</description>
    <properties>
        <java.version>1.8</java.version>
        <jjwt.version>0.10.6</jjwt.version>
    </properties>
    <dependencies>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.12</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </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>org.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>test</scope>
        </dependency>


        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt-api</artifactId>
            <version>${jjwt.version}</version>
        </dependency>
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt-impl</artifactId>
            <version>${jjwt.version}</version>
        </dependency>
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt-jackson</artifactId>
            <version>${jjwt.version}</version>
        </dependency>


        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time</artifactId>
            <version>2.10.10</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot</artifactId>
            <version>2.4.4</version>
        </dependency>


    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>

        <finalName>${artifactId}</finalName>
    </build>

</project>

main class-AuthServerApplication


@SpringBootApplication
public class AuthServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(AuthServerApplication.class, args);
    }
}

以下是 Tomcat 日志中的条目

catalina.log

21-Apr-2021 08:14:09.860 INFO [http-nio-8080-exec-2726] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive /opt/tomcat/webapps/auth-server.war
21-Apr-2021 08:14:11.828 INFO [http-nio-8080-exec-2726] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
21-Apr-2021 08:14:16.257 INFO [http-nio-8080-exec-2726] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive /opt/tomcat/webapps/auth-server.war has finished in 6,397 ms

localhost.log

21-Apr-2021 08:14:11.839 INFO [http-nio-8080-exec-2726] org.apache.catalina.core.ApplicationContext.log 2 Spring WebApplicationInitializers detected on classpath
21-Apr-2021 08:14:13.419 INFO [http-nio-8080-exec-2726] org.apache.catalina.core.ApplicationContext.log Initializing Spring embedded WebApplicationContext

manager.log

21-Apr-2021 08:12:04.977 INFO [http-nio-8080-exec-2623] org.apache.catalina.core.ApplicationContext.log HTMLManager: list: Listing contexts for virtual host 'localhost'
21-Apr-2021 08:14:09.806 INFO [http-nio-8080-exec-2726] org.apache.catalina.core.ApplicationContext.log HTMLManager: install: Installing web application '/auth-server' from '/tmp-war/auth-server.war'
21-Apr-2021 08:14:16.257 INFO [http-nio-8080-exec-2726] org.apache.catalina.core.ApplicationContext.log HTMLManager: list: Listing contexts for virtual host 'localhost'

localhost_access_log 文件中,我没有看到我尝试访问新部署的应用程序的条目。

我尝试过的一些东西:

@SpringBootApplication
public class AuthServerApplication extends SpringBootServletInitializer {
    public static void main(String[] args) {
        SpringApplication.run(AuthServerApplication.class, args);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(AuthServerApplication.class);
    }
}

    <properties>
        ...
        <start-class>
            com.apiauthentication.authserver.AuthServerApplication
        </start-class>
    </properties>
        <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>

任何人都有关于可能是什么问题的提示? 基本上我可以 运行 在本地 XAMPP 但不能在生产服务器上

添加来自 Piotr P. Karwasz 的评论作为答案。

What seems strange is the lack of entries in the access log. Are your sure that your production server is not behind a reverse proxy?

问题是我试图使用域名访问应用程序,但由于该域是使用 Plesk 管理的,并且该服务器上还有其他域,我不得不转到 Apache 设置域并为 HTTP 和 HTTPS 添加一些新的 ProxyPass 和 ProxyPassReverse 指令