Tomcat部署多个Sring Boot项目时Unable To Register MBean Exception的一种解决方法

Tomcat部署多个Sring Boot项目时出现org.springframework.jmx.export.UnableToRegisterMBeanException: Unable to register MBean [HikariDataSource (HikariPool-2)] with key ‘dataSource’ 异常的解决方法
异常如下
org.apache.catalina.core.ContainerBase.addChildInternal ContainerBase.addChild: start:
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[
Catalina].StandardHost[localhost].StandardContext[/dreamclock]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:754)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1140)
at org.apache.catalina.startup.HostConfig D e p l o y D i r e c t o r y . r u n ( H o s t C o n f i g . j a v a : 1875 ) a t j a v a . b a s e / j a v a . u t i l . c o n c u r r e n t . E x e c u t o r s DeployDirectory.run(HostConfig.java:1875) at java.base/java.util.concurrent.Executors DeployDirectory.run(HostConfig.java:1875)atjava.base/java.util.concurrent.ExecutorsRunnableAdapter.call(Executors.java:514)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135)
at java.base/java.util.concurrent.ThreadPoolExecutorKaTeX parse error: Expected 'EOF', got '\MyTomcat' at position 245: …ned in file [H:\̲M̲y̲T̲o̲m̲c̲a̲t̲\tomcat\webapps…doGetBeanKaTeX parse error: Expected 'EOF', got '\MyTomcat' at position 1975: …ned in file [H:\̲M̲y̲T̲o̲m̲c̲a̲t̲\tomcat\webapps…doGetBean 0 ( A b s t r a c t B e a n F a c t o r y . j a v a : 320 ) a t o r g . s p r i n g f r a m e w o r k . b e a n s . f a c t o r y . s u p p o r t . D e f a u l t S i n g l e t o n B e a n R e g i s t r y . g e t S i n g l e t o n ( D e f a u l t S i n g l e t o n B e a n R e g i s t r y . j a v a : 222 ) a t o r g . s p r i n g f r a m e w o r k . b e a n s . f a c t o r y . s u p p o r t . A b s t r a c t B e a n F a c t o r y . d o G e t B e a n ( A b s t r a c t B e a n F a c t o r y . j a v a : 318 ) a t o r g . s p r i n g f r a m e w o r k . b e a n s . f a c t o r y . s u p p o r t . A b s t r a c t B e a n F a c t o r y . g e t B e a n ( A b s t r a c t B e a n F a c t o r y . j a v a : 199 ) a t o r g . s p r i n g f r a m e w o r k . b e a n s . f a c t o r y . c o n f i g . D e p e n d e n c y D e s c r i p t o r . r e s o l v e C a n d i d a t e ( D e p e n d e n c y D e s c r i p t o r . j a v a : 277 ) a t o r g . s p r i n g f r a m e w o r k . b e a n s . f a c t o r y . s u p p o r t . D e f a u l t L i s t a b l e B e a n F a c t o r y . d o R e s o l v e D e p e n d e n c y ( D e f a u l t L i s t a b l e B e a n F a c t o r y . j a v a : 1244 ) a t o r g . s p r i n g f r a m e w o r k . b e a n s . f a c t o r y . s u p p o r t . D e f a u l t L i s t a b l e B e a n F a c t o r y . r e s o l v e D e p e n d e n c y ( D e f a u l t L i s t a b l e B e a n F a c t o r y . j a v a : 1164 ) a t o r g . s p r i n g f r a m e w o r k . b e a n s . f a c t o r y . s u p p o r t . C o n s t r u c t o r R e s o l v e r . r e s o l v e A u t o w i r e d A r g u m e n t ( C o n s t r u c t o r R e s o l v e r . j a v a : 857 ) a t o r g . s p r i n g f r a m e w o r k . b e a n s . f a c t o r y . s u p p o r t . C o n s t r u c t o r R e s o l v e r . c r e a t e A r g u m e n t A r r a y ( C o n s t r u c t o r R e s o l v e r . j a v a : 760 ) . . . 32 m o r e C a u s e d b y : o r g . s p r i n g f r a m e w o r k . b e a n s . f a c t o r y . B e a n C r e a t i o n E x c e p t i o n : E r r o r c r e a t i n g b e a n w i t h n a m e ′ c l o c k I n R e c o r d R e p o s i t o r y ′ : I n v o c a t i o n o f i n i t m e t h o d f a i l e d ; n e s t e d e x c e p t i o n i s j a v a . l a n g . I l l e g a l A r g u m e n t E x c e p t i o n : N o t a m a n a g e d t y p e : c l a s s c o m . x i a o m o . d r e a m c l o c k . m o d e l . c l o c k i n . C l o c k I n R e c o r d a t o r g . s p r i n g f r a m e w o r k . b e a n s . f a c t o r y . s u p p o r t . A b s t r a c t A u t o w i r e C a p a b l e B e a n F a c t o r y . i n i t i a l i z e B e a n ( A b s t r a c t A u t o w i r e C a p a b l e B e a n F a c t o r y . j a v a : 1745 ) a t o r g . s p r i n g f r a m e w o r k . b e a n s . f a c t o r y . s u p p o r t . A b s t r a c t A u t o w i r e C a p a b l e B e a n F a c t o r y . d o C r e a t e B e a n ( A b s t r a c t A u t o w i r e C a p a b l e B e a n F a c t o r y . j a v a : 576 ) a t o r g . s p r i n g f r a m e w o r k . b e a n s . f a c t o r y . s u p p o r t . A b s t r a c t A u t o w i r e C a p a b l e B e a n F a c t o r y . c r e a t e B e a n ( A b s t r a c t A u t o w i r e C a p a b l e B e a n F a c t o r y . j a v a : 498 ) a t o r g . s p r i n g f r a m e w o r k . b e a n s . f a c t o r y . s u p p o r t . A b s t r a c t B e a n F a c t o r y . l a m b d a 0(AbstractBeanFactory.java:320) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:277) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1244) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1164) at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:857) at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:760) ... 32 more Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name &#x27;clockInRecordRepository&#x27;: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Not a managed type: class com.xiaomo.dreamclock.model.clockin.ClockInRecord at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1745) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:576) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda 0(AbstractBeanFactory.java:320)atorg.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)atorg.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)atorg.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:277)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1244)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1164)atorg.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:857)atorg.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:760)...32moreCausedby:org.springframework.beans.factory.BeanCreationException:ErrorcreatingbeanwithnameclockInRecordRepository:Invocationofinitmethodfailed;nestedexceptionisjava.lang.IllegalArgumentException:Notamanagedtype:classcom.xiaomo.dreamclock.model.clockin.ClockInRecordatorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1745)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:576)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498)atorg.springframework.beans.factory.support.AbstractBeanFactory.lambdadoGetBean 0 ( A b s t r a c t B e a n F a c t o r y . j a v a : 320 ) a t o r g . s p r i n g f r a m e w o r k . b e a n s . f a c t o r y . s u p p o r t . D e f a u l t S i n g l e t o n B e a n R e g i s t r y . g e t S i n g l e t o n ( D e f a u l t S i n g l e t o n B e a n R e g i s t r y . j a v a : 222 ) a t o r g . s p r i n g f r a m e w o r k . b e a n s . f a c t o r y . s u p p o r t . A b s t r a c t B e a n F a c t o r y . d o G e t B e a n ( A b s t r a c t B e a n F a c t o r y . j a v a : 318 ) a t o r g . s p r i n g f r a m e w o r k . b e a n s . f a c t o r y . s u p p o r t . A b s t r a c t B e a n F a c t o r y . g e t B e a n ( A b s t r a c t B e a n F a c t o r y . j a v a : 199 ) a t o r g . s p r i n g f r a m e w o r k . b e a n s . f a c t o r y . c o n f i g . D e p e n d e n c y D e s c r i p t o r . r e s o l v e C a n d i d a t e ( D e p e n d e n c y D e s c r i p t o r . j a v a : 277 ) a t o r g . s p r i n g f r a m e w o r k . b e a n s . f a c t o r y . s u p p o r t . D e f a u l t L i s t a b l e B e a n F a c t o r y . d o R e s o l v e D e p e n d e n c y ( D e f a u l t L i s t a b l e B e a n F a c t o r y . j a v a : 1244 ) a t o r g . s p r i n g f r a m e w o r k . b e a n s . f a c t o r y . s u p p o r t . D e f a u l t L i s t a b l e B e a n F a c t o r y . r e s o l v e D e p e n d e n c y ( D e f a u l t L i s t a b l e B e a n F a c t o r y . j a v a : 1164 ) a t o r g . s p r i n g f r a m e w o r k . b e a n s . f a c t o r y . s u p p o r t . C o n s t r u c t o r R e s o l v e r . r e s o l v e A u t o w i r e d A r g u m e n t ( C o n s t r u c t o r R e s o l v e r . j a v a : 857 ) a t o r g . s p r i n g f r a m e w o r k . b e a n s . f a c t o r y . s u p p o r t . C o n s t r u c t o r R e s o l v e r . c r e a t e A r g u m e n t A r r a y ( C o n s t r u c t o r R e s o l v e r . j a v a : 760 ) . . . 46 m o r e C a u s e d b y : j a v a . l a n g . I l l e g a l A r g u m e n t E x c e p t i o n : N o t a m a n a g e d t y p e : c l a s s c o m . x i a o m o . d r e a m c l o c k . m o d e l . c l o c k i n . C l o c k I n R e c o r d a t o r g . h i b e r n a t e . m e t a m o d e l . i n t e r n a l . M e t a m o d e l I m p l . m a n a g e d T y p e ( M e t a m o d e l I m p l . j a v a : 552 ) a t o r g . s p r i n g f r a m e w o r k . d a t a . j p a . r e p o s i t o r y . s u p p o r t . J p a M e t a m o d e l E n t i t y I n f o r m a t i o n . &lt; i n i t &gt; ( J p a M e t a m o d e l E n t i t y I n f o r m a t i o n . j a v a : 74 ) a t o r g . s p r i n g f r a m e w o r k . d a t a . j p a . r e p o s i t o r y . s u p p o r t . J p a E n t i t y I n f o r m a t i o n S u p p o r t . g e t E n t i t y I n f o r m a t i o n ( J p a E n t i t y I n f o r m a t i o n S u p p o r t . j a v a : 66 ) a t o r g . s p r i n g f r a m e w o r k . d a t a . j p a . r e p o s i t o r y . s u p p o r t . J p a R e p o s i t o r y F a c t o r y . g e t E n t i t y I n f o r m a t i o n ( J p a R e p o s i t o r y F a c t o r y . j a v a : 188 ) a t o r g . s p r i n g f r a m e w o r k . d a t a . j p a . r e p o s i t o r y . s u p p o r t . J p a R e p o s i t o r y F a c t o r y . g e t T a r g e t R e p o s i t o r y ( J p a R e p o s i t o r y F a c t o r y . j a v a : 139 ) a t o r g . s p r i n g f r a m e w o r k . d a t a . j p a . r e p o s i t o r y . s u p p o r t . J p a R e p o s i t o r y F a c t o r y . g e t T a r g e t R e p o s i t o r y ( J p a R e p o s i t o r y F a c t o r y . j a v a : 123 ) a t o r g . s p r i n g f r a m e w o r k . d a t a . j p a . r e p o s i t o r y . s u p p o r t . J p a R e p o s i t o r y F a c t o r y . g e t T a r g e t R e p o s i t o r y ( J p a R e p o s i t o r y F a c t o r y . j a v a : 64 ) a t o r g . s p r i n g f r a m e w o r k . d a t a . r e p o s i t o r y . c o r e . s u p p o r t . R e p o s i t o r y F a c t o r y S u p p o r t . g e t R e p o s i t o r y ( R e p o s i t o r y F a c t o r y S u p p o r t . j a v a : 305 ) a t o r g . s p r i n g f r a m e w o r k . d a t a . r e p o s i t o r y . c o r e . s u p p o r t . R e p o s i t o r y F a c t o r y B e a n S u p p o r t . l a m b d a 0(AbstractBeanFactory.java:320) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:277) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1244) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1164) at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:857) at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:760) ... 46 more Caused by: java.lang.IllegalArgumentException: Not a managed type: class com.xiaomo.dreamclock.model.clockin.ClockInRecord at org.hibernate.metamodel.internal.MetamodelImpl.managedType(MetamodelImpl.java:552) at org.springframework.data.jpa.repository.support.JpaMetamodelEntityInformation.&lt;init&gt;(JpaMetamodelEntityInformation.java:74) at org.springframework.data.jpa.repository.support.JpaEntityInformationSupport.getEntityInformation(JpaEntityInformationSupport.java:66) at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getEntityInformation(JpaRepositoryFactory.java:188) at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:139) at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:123) at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:64) at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:305) at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.lambda 0(AbstractBeanFactory.java:320)atorg.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)atorg.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)atorg.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:277)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1244)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1164)atorg.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:857)atorg.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:760)...46moreCausedby:java.lang.IllegalArgumentException:Notamanagedtype:classcom.xiaomo.dreamclock.model.clockin.ClockInRecordatorg.hibernate.metamodel.internal.MetamodelImpl.managedType(MetamodelImpl.java:552)atorg.springframework.data.jpa.repository.support.JpaMetamodelEntityInformation.<init>(JpaMetamodelEntityInformation.java:74)atorg.springframework.data.jpa.repository.support.JpaEntityInformationSupport.getEntityInformation(JpaEntityInformationSupport.java:66)atorg.springframework.data.jpa.repository.support.JpaRepositoryFactory.getEntityInformation(JpaRepositoryFactory.java:188)atorg.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:139)atorg.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:123)atorg.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:64)atorg.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:305)atorg.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.lambdaafterPropertiesSet$5(RepositoryFactoryBeanSupport.java:297)
at org.springframework.data.util.Lazy.getNullable(Lazy.java:211)
at org.springframework.data.util.Lazy.get(Lazy.java:94)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:300)
at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:119)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1804)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1741)
… 57 more

24-Feb-2019 23:48:09.828 ÑÏÖØ [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Error deploying web application directory [H:\MyTomcat\tomcat\webapps\dreamclock]
java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/dreamclock]]
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:758)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1140)
at org.apache.catalina.startup.HostConfig D e p l o y D i r e c t o r y . r u n ( H o s t C o n f i g . j a v a : 1875 ) a t j a v a . b a s e / j a v a . u t i l . c o n c u r r e n t . E x e c u t o r s DeployDirectory.run(HostConfig.java:1875) at java.base/java.util.concurrent.Executors DeployDirectory.run(HostConfig.java:1875)atjava.base/java.util.concurrent.ExecutorsRunnableAdapter.call(Executors.java:514)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:844)

24-Feb-2019 23:48:09.844 ÐÅÏ¢ [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [H:\MyTomcat\tomcat\webapps\dreamclock] has finished in [17,080] ms
24-Feb-2019 23:48:10.449 ÐÅÏ¢ [localhost-startStop-1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
24-Feb-2019 23:48:10.512 ÐÅÏ¢ [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [H:\MyTomcat\tomcat\webapps\pavilion]
24-Feb-2019 23:48:13.968 ÐÅÏ¢ [localhost-startStop-1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
24-Feb-2019 23:48:26.179 ÑÏÖØ [localhost-startStop-1] org.apache.catalina.core.ContainerBase.addChildInternal ContainerBase.addChild: start:
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/pavilion]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:754)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1140)
at org.apache.catalina.startup.HostConfig D e p l o y D i r e c t o r y . r u n ( H o s t C o n f i g . j a v a : 1875 ) a t j a v a . b a s e / j a v a . u t i l . c o n c u r r e n t . E x e c u t o r s DeployDirectory.run(HostConfig.java:1875) at java.base/java.util.concurrent.Executors DeployDirectory.run(HostConfig.java:1875)atjava.base/java.util.concurrent.ExecutorsRunnableAdapter.call(Executors.java:514)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135)
at java.base/java.util.concurrent.ThreadPoolExecutor W o r k e r . r u n ( T h r e a d P o o l E x e c u t o r . j a v a : 635 ) a t j a v a . b a s e / j a v a . l a n g . T h r e a d . r u n ( T h r e a d . j a v a : 844 ) C a u s e d b y : o r g . s p r i n g f r a m e w o r k . j m x . e x p o r t . U n a b l e T o R e g i s t e r M B e a n E x c e p t i o n : U n a b l e t o r e g i s t e r M B e a n [ H i k a r i D a t a S o u r c e ( H i k a r i P o o l − 2 ) ] w i t h k e y ′ d a t a S o u r c e ′ ; n e s t e d e x c e p t i o n i s j a v a x . m a n a g e m e n t . I n s t a n c e A l r e a d y E x i s t s E x c e p t i o n : c o m . z a x x e r . h i k a r i : n a m e = d a t a S o u r c e , t y p e = H i k a r i D a t a S o u r c e a t o r g . s p r i n g f r a m e w o r k . j m x . e x p o r t . M B e a n E x p o r t e r . r e g i s t e r B e a n N a m e O r I n s t a n c e ( M B e a n E x p o r t e r . j a v a : 625 ) a t o r g . s p r i n g f r a m e w o r k . j m x . e x p o r t . M B e a n E x p o r t e r . l a m b d a Worker.run(ThreadPoolExecutor.java:635) at java.base/java.lang.Thread.run(Thread.java:844) Caused by: org.springframework.jmx.export.UnableToRegisterMBeanException: Unable to register MBean [HikariDataSource (HikariPool-2)] with key &#x27;dataSource&#x27;; nested exception is javax.management.InstanceAlreadyExistsException: com.zaxxer.hikari:name=dataSource,type=HikariDataSource at org.springframework.jmx.export.MBeanExporter.registerBeanNameOrInstance(MBeanExporter.java:625) at org.springframework.jmx.export.MBeanExporter.lambda Worker.run(ThreadPoolExecutor.java:635)atjava.base/java.lang.Thread.run(Thread.java:844)Causedby:org.springframework.jmx.export.UnableToRegisterMBeanException:UnabletoregisterMBean[HikariDataSource(HikariPool2)]withkeydataSource;nestedexceptionisjavax.management.InstanceAlreadyExistsException:com.zaxxer.hikari:name=dataSource,type=HikariDataSourceatorg.springframework.jmx.export.MBeanExporter.registerBeanNameOrInstance(MBeanExporter.java:625)atorg.springframework.jmx.export.MBeanExporter.lambdaregisterBeans$2(MBeanExporter.java:551)
at java.base/java.util.HashMap.forEach(HashMap.java:1341)
at org.springframework.jmx.export.MBeanExporter.registerBeans(MBeanExporter.java:551)
at org.springframework.jmx.export.MBeanExporter.afterSingletonsInstantiated(MBeanExporter.java:434)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:863)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:863)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:157)
at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:137)
at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:91)
at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:171)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5245)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
… 10 more
Caused by: javax.management.InstanceAlreadyExistsException: com.zaxxer.hikari:name=dataSource,type=HikariDataSource
at java.management/com.sun.jmx.mbeanserver.Repository.addMBean(Repository.java:436)
at java.management/com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerWithRepository(DefaultMBeanServerInterceptor.java:1855)
at java.management/com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerDynamicMBean(DefaultMBeanServerInterceptor.java:955)
at java.management/com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerObject(DefaultMBeanServerInterceptor.java:890)
at java.management/com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(DefaultMBeanServerInterceptor.java:320)
at java.management/com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(JmxMBeanServer.java:522)
at org.springframework.jmx.support.MBeanRegistrationSupport.doRegister(MBeanRegistrationSupport.java:137)
at org.springframework.jmx.export.MBeanExporter.registerBeanInstance(MBeanExporter.java:671)
at org.springframework.jmx.export.MBeanExporter.registerBeanNameOrInstance(MBeanExporter.java:615)
… 27 more
环境记录
Spring Boot项目一:

部署方式:war包;数据库:MySQL;数据访问方式:JPA

Spring Boot项目二:

部署方式:war包;数据库:MySQL;数据访问方式:JPA

问题分析
通过查看log,可以得出是Spring创建 Controller:clockInRecordController时发生了错误,错误原因是通过构造函数传入clockInRecordServiceImp这一Service的实现时出错了;这一Service出错的原因是在构造函数中传入的Repository出错了;Repository出错的原因是调用初始化方法失败;最内层的原因是:ClockInRecord不是一个被管理的类!

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name ‘clockInRecordController’ defined in file
[H:\MyTomcat\tomcat\webapps\dreamclock\WEB-
INF\classes\com\xiaomo\dreamclock\controller\clockin
ClockInRecordController.class]: Unsatisfied
dependency expressed through constructor parameter 0; nested exception is
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name ‘clockInRecordServiceImp’ defined in file
[H:\MyTomcat\tomcat\webapps\dreamclock\WEB-
INF\classes\com\xiaomo\dreamclock\service\clockin\imp
ClockInRecordServiceImp.class]: Unsatisfied dependency expressed
through constructor parameter 0; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean with name
‘clockInRecordRepository’: Invocation of init method failed; nested exception is
java.lang.IllegalArgumentException: Not a managed type: class
com.xiaomo.dreamclock.model.clockin.ClockInRecord
到这里,自然要考虑为啥ClockInRecord这一实体类没有被Spring 管理了。而这就误入歧途了!因为这仍然不是根本原因;

当然,针对这一问题,我也是问过度娘的~ 基本的原因无非是Spring Boot扫描包的时候并没有将实体类扫描到,或者是实体类缺少了@Entity注解;针对前一种可能,我在遇到org.hibernate.AnnotationException异常时就进行了扫描相关的配置;至于缺少@Entity注解,更不是问题所在:加没加该注解,自己还不清楚吗?

另外,因为单独部署Pavilion和DreamClock项目时并无问题,所以上面提到的异常链,仍然是不全的。

一度以为是云主机配置太差,内存不够导致一些组件没能正常工作。。。。但是在本地tomcat里部署时也出现了该问题,这就排除了硬件限制;

接着往下看,就发现了问题所在:

Caused by: org.springframework.jmx.export.UnableToRegisterMBeanException: Unable to register MBean [HikariData

应该是dataSource注册失败,导致了这一系列问题;内部原因是因为dataSource已经存在了,或者说已经在注册过了。

问题解决
在StackOverflow上找到了该问题及其回答:unable-to-register-mbean

简单来说,是JMX出现了问题。Spring 默认JMX是开启的,所以解决方法之一就是在application.properties或者application.yml里配置spring.jmx.enabled=false;

办法2:

在application中各自配置

spring.jmx.default-domain=project1

spring.jmx.default-domain=project2

以保证domain是两个不一样的

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值