我面临一个非常奇怪的问题。当我使用Spring Tools Suit创建war文件并将其部署到Tomcat时,一切正常。但是如果我部署另一个Spring Boot war文件(一个不同的Spring启动项目),那么最新版本会抛出异常。但只要其中只有一个上传,那么它们都可以正常工作,没有例外。
以下是我从其中一个war文件中获得的例外情况。只有在Tomcat上部署了另一个war文件时才会出现这种情况,生成的日志太长而无法在此发布,所以我在这里发布了
以下是服务器信息
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时项目作为war文件所做的更改
@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);
}
}
我的application.properties
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
这里有什么问题?
答案 0 :(得分:0)
您收到JMX InstanceAlreadyExists异常。为每个应用程序中的以下属性指定唯一值
spring.application.name
spring.jmx.default-domain
希望这会有所帮助。