我面临一个非常奇怪的问题。当我使用Spring工具套装创建一个war文件并将其部署到Tomcat时,一切都正常。但是如果我部署另一个SpringBootWar文件(一个不同的SpringBoot项目),那么最新的文件将抛出异常。但只要其中一个被上传,他们都会正常工作,没有例外。
以下是我从一个战争文件中得到的例外。只有当我在Tomcat上部署了另一个war文件时才会发生这种情况,生成的日志太长,无法在这里发布,所以我将它们发布在这里。
https://pastebin.com/6rnAsWT8
以下是服务器信息
root@localhost:/usr/share/tomcat8/bin# ./version.sh
Using CATALINA_BASE: /usr/share/tomcat8
Using CATALINA_HOME: /usr/share/tomcat8
Using CATALINA_TMPDIR: /usr/share/tomcat8/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/share/tomcat8/bin/bootstrap.jar:/usr/share/tomcat8/bin/tomcat-juli.jar
Server version: Apache Tomcat/8.5.14 (Debian)
Server built: Sep 3 2017 17:51:58 UTC
Server number: 8.5.14.0
OS Name: Linux
OS Version: 4.9.0-6-amd64
Architecture: amd64
JVM Version: 1.8.0_171-8u171-b11-1~deb9u1-b11
JVM Vendor: Oracle Corporation
下面是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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.imageapi</groupId>
<artifactId>ImageAPI</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>ImageAPI</name>
<description></description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.2.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</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-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</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.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api -->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
下面是我为这个项目所做的修改,当上传到Tomcat时,它将作为一个战争文件工作。
@SpringBootApplication
public class ImageApiApplication extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(ImageApiApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(ImageApiApplication.class, args);
}
}
我的应用程序属性
spring.datasource.url=jdbc:postgresql://serverup:5432/mydb
spring.datasource.username=mydb
spring.datasource.password=mypass
spring.jpa.generate-ddl=true
spring.security.user.name=myusername
spring.security.user.password=mypass
spring.thymeleaf.cache=false
spring.application.name=imageapi
这里有什么问题?