tomcat的webapps下部署多项目报错Unable to register MBean [HikariDataSource (null)] with key ‘dataSource’

迎刃而解 盛行 2个月前 (01-07) 180次浏览 已收录 0个评论 扫描二维码
文章目录
[隐藏]

1.简介

最近需要将线上跑的多个容器中的项目迁出,其中有一个项目有两个war包,迁出之后部署在同一个虚机上,造成服务启动异常,报出Unable to register MBean [HikariDataSource (null)] with key ‘dataSource’的错误,大概意思就是已经注册了数据源不能重复在注册了,造成了冲突。

2.报错

严重: ContainerBase.addChild: start: 
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/pushdata]]
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:162)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:899)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:875)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)
	at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1092)
	at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1984)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Caused by: 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
	at org.springframework.jmx.export.MBeanExporter.registerBeanNameOrInstance(MBeanExporter.java:628)
	at org.springframework.jmx.export.MBeanExporter.registerBeans(MBeanExporter.java:550)
	at org.springframework.jmx.export.MBeanExporter.afterSingletonsInstantiated(MBeanExporter.java:432)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:781)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
	at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
	at org.springframework.boot.web.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:154)
	at org.springframework.boot.web.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:134)
	at org.springframework.boot.web.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:87)
	at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:169)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5632)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
	... 10 more
Caused by: javax.management.InstanceAlreadyExistsException: com.zaxxer.hikari:name=dataSource,type=HikariDataSource
	at com.sun.jmx.mbeanserver.Repository.addMBean(Repository.java:437)
	at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerWithRepository(DefaultMBeanServerInterceptor.java:1898)
	at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerDynamicMBean(DefaultMBeanServerInterceptor.java:966)
	at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerObject(DefaultMBeanServerInterceptor.java:900)
	at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(DefaultMBeanServerInterceptor.java:324)
	at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(JmxMBeanServer.java:522)
	at org.springframework.jmx.support.MBeanRegistrationSupport.doRegister(MBeanRegistrationSupport.java:195)
	at org.springframework.jmx.export.MBeanExporter.registerBeanInstance(MBeanExporter.java:674)
	at org.springframework.jmx.export.MBeanExporter.registerBeanNameOrInstance(MBeanExporter.java:618)
	... 25 more

一月 07, 2021 9:16:30 上午 org.apache.catalina.startup.HostConfig deployWAR
严重: Error deploying web application archive /var/lib/tomcat/webapps/pushdata.war
java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/pushdata]]
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:903)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:875)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)
	at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1092)
	at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1984)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)

一月 07, 2021 9:16:30 上午 org.apache.catalina.startup.HostConfig deployWAR

3.处理方法

webapps各项目的application.yml配置文件增加如下配置项:
# jmx 默认域,用于区分项目
spring.jmx.default-domain=项目名称(名称任意,建议项目名称)
例如以下配置文件:

vim /usr/share/tomcat/webapps/cupboard/WEB-INF/classes/application.yml
spring:
  jmx.default-domain: cupboard #增加此配置项,多个项目不要重复即可
  datasource:
    url: jdbc:mysql://itbkz.com:3306/cupboard?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC
    username: 用户名
    password: 密码
    driver-class-name: com.mysql.jdbc.Driver
    type: com.zaxxer.hikari.HikariDataSource
    hikari:
      minimum-idle: 5
      maximum-pool-size: 15
      auto-commit: true
      idle-timeout: 30000
      pool-name: DateHikariCP1
      max-lifetime: 1800000
      connection-timeout: 30000
      connection-test-query: SELECT 1

  http:
    encoding:
      charset: utf-8
      enabled: true
      force: true

  thymeleaf:
    mode: LEGACYHTML5
    servlet:
      content-type: text/html
    cache: false

mybatis:
  mapper-locations: classpath:mapper/*Mapper.xml
  config-location: classpath:mapper/mybatis-config.xml


logging:
  level:
    root: info
####    com.itbkz.query.cupboardquery.dao: debug
  file: /data/tomcat7/logs/cupboard_info.log
  pattern:
    console: "%d %green([%t]) %magenta(%-5p) %cyan(%c) - %m%n"
    file: "%d %thread %-5level -%file:%line- %msg%n"
以上配置文件已经过处理或修改

IT博客站版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:tomcat的webapps下部署多项目报错Unable to register MBean [HikariDataSource (null)] with key ‘dataSource’
喜欢 (0)
[使用支付宝扫码]
分享 (0)
盛行
关于作者:
企业应用技术爱好者,喜欢分享知识。如果文章中有错误,欢迎指正,谢谢。
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址