spring boot 引入MongoDB启动报错
java.lang.IllegalStateException: Failed to introspect Class [io.micrometer.core.instrument.binder.mongodb.DefaultMongoConnectionPoolTagsProvider] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2]
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:485) ~[spring-core-5.3.26.jar:5.3.26]
at org.springframework.util.ReflectionUtils.doWithLocalMethods(ReflectionUtils.java:321) ~[spring-core-5.3.26.jar:5.3.26]
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.buildLifecycleMetadata(InitDestroyAnnotationBeanPostProcessor.java:232) ~[spring-beans-5.3.26.jar:5.3.26]
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.findLifecycleMetadata(InitDestroyAnnotationBeanPostProcessor.java:210) ~[spring-beans-5.3.26.jar:5.3.26]
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(InitDestroyAnnotationBeanPostProcessor.java:149) ~[spring-beans-5.3.26.jar:5.3.26]
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(CommonAnnotationBeanPostProcessor.java:305) ~[spring-context-5.3.26.jar:5.3.26]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:1116) ~[spring-beans-5.3.26.jar:5.3.26]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594) ~[spring-beans-5.3.26.jar:5.3.26] ... 29
common frames omitted Caused by: java.lang.NoClassDefFoundError: com/mongodb/event/ConnectionPoolCreatedEvent at java.lang.Class.getDeclaredMethods0(Native Method) ~[na:1.8.0_401]
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) ~[na:1.8.0_401] at java.lang.Class.getDeclaredMethods(Class.java:1975) ~[na:1.8.0_401]
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:467) ~[spring-core-5.3.26.jar:5.3.26] ... 36
common frames omitted Caused by: java.lang.ClassNotFoundException: com.mongodb.event.ConnectionPoolCreatedEvent
at java.net.URLClassLoader.findClass(URLClassLoader.java:387) ~[na:1.8.0_401] at java.lang.ClassLoader.loadClass(ClassLoader.java:418) ~[na:1.8.0_401]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:359) ~[na:1.8.0_401] at java.lang.ClassLoader.loadClass(ClassLoader.java:351) ~[na:1.8.0_401] ... 40
common frames omitted
pom.xml
<dependency><groupId>org.mongodb</groupId><artifactId>mongo-java-driver</artifactId><version>3.8.2</version></dependency>
要确认版本是否对应
https://docs.spring.io/spring-data/mongodb/docs/3.4.9/reference/html/
发现版本不对,但是mongo-java-driver又没有4.0以上的
加如下依赖
<dependency><groupId>org.mongodb</groupId><artifactId>mongodb-driver-sync</artifactId><version>4.7.0</version>
</dependency>
版本不要太高,4.9以上可能会有Loggers报错