我正在使用 Spring MVC。添加了 Spring 的所有依赖项,因此应用程序想要为 io/micrometer/observation/transport/RequestReplyReceiverContext 添加 micrometer-core,我做到了
我的pom.xml
> `<dependency>
> <groupId>io.micrometer</groupId>
> <artifactId>micrometer-core</artifactId>
> <version>1.12.2</version>
> </dependency>`
并且库已添加到我的项目中,因此在执行时....
> Context initialization failed
> org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping': Lookup method resolution failed
> at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.checkLookupMethods(AutowiredAnnotationBeanPostProcessor.java:497)
> at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:367)
> at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:1294)
> at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1189)
> at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:562)
> at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:522)
> at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:326)
> at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
> at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:324)
> at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
> at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:975)
> at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:962)
> at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:624)
> at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:394)
> at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:274)
> at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:102)
> at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4438)
> at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:4876)
> at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:171)
> at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1332)
> at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1322)
> at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
> at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
> at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:145)
> at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:866)
> at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:845)
> at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:171)
> at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1332)
> at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1322)
> at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
> at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
> at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:145)
> at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:866)
> at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:240)
> at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:171)
> at org.apache.catalina.core.StandardService.startInternal(StandardService.java:433)
> at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:171)
> at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:917)
> at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:171)
> at org.apache.catalina.startup.Catalina.start(Catalina.java:795)
> at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
> at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.base/java.lang.reflect.Method.invoke(Method.java:568)
> at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:347)
> at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:478)
> Caused by: java.lang.IllegalStateException: Failed to introspect Class [org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping] from ClassLoader [ParallelWebappClassLoader
> context: GameZone
> delegate: false
> Parent Classloader:
> java.net.URLClassLoader@100fc185
> ]
> at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:483)
> at org.springframework.util.ReflectionUtils.doWithLocalMethods(ReflectionUtils.java:320)
> at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.checkLookupMethods(AutowiredAnnotationBeanPostProcessor.java:475)
> 45 more
> Caused by: java.lang.NoClassDefFoundError: io/micrometer/observation/transport/RequestReplyReceiverContext
> at java.base/java.lang.ClassLoader.defineClass1(Native Method)
> at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1017)
> at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
> at org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2352)
> at org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:800)
> at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1317)
> at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1165)
> at java.base/java.lang.Class.getDeclaredMethods0(Native Method)
> at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3402)
> at java.base/java.lang.Class.getDeclaredMethods(Class.java:2504)
> at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:465)
> 47 more
> Caused by: java.lang.ClassNotFoundException: io.micrometer.observation.transport.RequestReplyReceiverContext
> at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1353)
> at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1165)
> 58 more`
>
这里有什么问题?
问题很可能是你的依赖关系。
您唯一需要的是执行器和注册表,例如:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
未定义版本,版本应来自 Spring Boot BOM。