---
title: "解决tomcat部署两个SpringBoot应用提示InstanceAlreadyExistsException"
author: "wallimn"
date: "2019-06-30T11:49:26Z"
tags: []
categories: ["编程语言"]
slug: "tomcat-springboot-instancealreadyexistsexception"
draft: false
lastmod: "2019-06-30T11:52:42Z"
id: 2442266
url: "https://wallimn.iteye.com/blog/2442266"
---

两个SpringBoot应用部署在一个Tomcat中，单独部署都是正常的，一起部署，后面起动的应用就会报InstanceAlreadyExistsException，启动失败。

　　<span style="color:darkred">**具体信息：**</span>
Application run failed
org.springframework.jmx.export.UnableToRegisterMBeanException: Unable to register MBean  with key 'dataSource'; nested exception is javax.management.InstanceAlreadyExistsException: com.zaxxer.hikari:name=dataSource,type=HikariDataSource

　　仔细查看异常，发现是spring注册MBean的问题，原因很简单：同一个domain里面的MBean要求name唯一。因此只要把不同的应用放到不同的doman问题便可以解决。
　　在每一个SpringBoot应用的application.properties中添加如下语句：

<span style="color:darkred">
      spring.jmx.default-domain=any_domain_of_your_like
</span>