两个SpringBoot应用部署在一个Tomcat中,单独部署都是正常的,一起部署,后面起动的应用就会报InstanceAlreadyExistsException,启动失败。
解决方法(已验证):
https://blog.csdn.net/MrLi_IT/article/details/83274089
(未验证)
https://www.iteye.com/blog/wallimn-2442266
具体信息:
Application run failed
org.springframework.jmx.export.UnableToRegisterMBeanException: Unable to register MBean [HikariDataSource (null)] 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中添加如下语句:
spring.jmx.default-domain=any_domain_of_your_like