我已经创建了一个spring引导应用程序,它具有Spring Security ,以公开一些restapi端点。我使用内置的intellij ultimate spring初始化器创建了这个项目。
Spring版本:2.4.4
类型:maven
java版本:8
Package :战争
当我在intellij中运行应用程序并启动tomcat9.0.44的一个示例时。
然后我创建了一个war文件,使用maven>包,在我的pc的本地xampp安装上进行测试(我使用tomcat 8.5.53。原因是,这是在我们的生产环境中可用的tomcat版本,我最终要部署到该版本。)
我使用tomcat管理器进行了部署,它在那里运行也没有任何问题。
然后,我将war转移到生产服务器,并使用tomcat manager ui进行部署。
我可以在manager中看到它已部署并且正在运行。
生产服务器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>
主类authserverapplication
@SpringBootApplication
public class AuthServerApplication {
public static void main(String[] args) {
SpringApplication.run(AuthServerApplication.class, args);
}
}
下面是tomcat日志中的条目
卡特琳娜.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
管理器.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\u access\u日志文件中,我看不到访问新部署的应用程序的任何条目。
我尝试过的一些事情:
在我的主类上扩展springbootservletinitializer并重写configure方法
@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);
}
}
在pom.xml的properties部分添加start类
<properties>
...
<start-class>
com.apiauthentication.authserver.AuthServerApplication
</start-class>
</properties>
为springbootstartertomcat在springbootstarter站点中添加一个排除项
<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上运行,但不能在生产服务器上运行
1条答案
按热度按时间tzxcd3kk1#
添加来自piotr p的评论。卡瓦兹作为答案。
奇怪的是访问日志中缺少条目。您确定生产服务器不在反向代理后面吗?
问题是,我试图使用域名访问应用程序,但由于该域是使用plesk管理的,而且该服务器上还有其他域,因此我必须转到该域的apache设置,并为http和https添加一些新的proxypass和proxypassreverse指令