[春季] [执行者]无法处理配置类的导入候选项

时间:2019-04-22 09:04:43

标签: java spring spring-boot-actuator

我正在尝试在我的spring项目中实现执行器(不是spring boot)。我在pom文件中添加了以下依赖项:

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-actuator</artifactId>
        <version>1.3.5.RELEASE</version>
    </dependency>

还添加了以下类别:

import java.util.Collection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.autoconfigure.EndpointAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.PublicMetricsAutoConfiguration;
import org.springframework.boot.actuate.endpoint.MetricsEndpoint;
import org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping;
import org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter;
import org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

@Configuration
@Import({EndpointAutoConfiguration.class, PublicMetricsAutoConfiguration.class})
public class SpringBootActuatorConfigBindings {

    @Bean
    @Autowired
    public EndpointHandlerMapping endpointHandlerMapping(Collection<? extends MvcEndpoint> endpoints) {
        return new EndpointHandlerMapping(endpoints);
    }

    @Bean
    @Autowired
    public EndpointMvcAdapter metricsEndPoint(MetricsEndpoint delegate) {
        return new EndpointMvcAdapter(delegate);
    }
}

但是在运行时,我遇到以下错误:

  

[本地] [] [错误] [2019-04-22T14:24:47,347] [控制台扫描器]   [work.web.context.ContextLoader]上下文初始化失败   org.springframework.beans.factory.BeanDefinitionStoreException:失败   处理配置类的导入候选   [com.mycompany.ans.processor.bindings.ProcessorBindings];嵌套的   异常为java.lang.IllegalStateException:无法自省   类上的带注释的方法   com.mycompany.ans.processor.bindings.SpringBootActuatorConfigBindings           在org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:599)   〜[spring-context-5.1.1.RELEASE.jar:5.1.1.RELEASE]           在org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:302)   〜[spring-context-5.1.1.RELEASE.jar:5.1.1.RELEASE]           在org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:242)   〜[spring-context-5.1.1.RELEASE.jar:5.1.1.RELEASE]           在org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:199)   〜[spring-context-5.1.1.RELEASE.jar:5.1.1.RELEASE]           在org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:167)   〜[spring-context-5.1.1.RELEASE.jar:5.1.1.RELEASE]           在org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:315)处   〜[spring-context-5.1.1.RELEASE.jar:5.1.1.RELEASE]           在org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:232)处   〜[spring-context-5.1.1.RELEASE.jar:5.1.1.RELEASE]           在org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:275)   〜[spring-context-5.1.1.RELEASE.jar:5.1.1.RELEASE]           在org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:95)   〜[spring-context-5.1.1.RELEASE.jar:5.1.1.RELEASE]           在org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:691)处   〜[spring-context-5.1.1.RELEASE.jar:5.1.1.RELEASE]           在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:528)   〜[spring-context-5.1.1.RELEASE.jar:5.1.1.RELEASE]           在org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:400)   〜[spring-web-5.1.1.RELEASE.jar:5.1.1.RELEASE]           在org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:291)   [spring-web-5.1.1.RELEASE.jar:5.1.1.RELEASE]           在org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:103)   [spring-web-5.1.1.RELEASE.jar:5.1.1.RELEASE]           在org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:952)处   [jetty-server-9.4.12.v20180830.jar:9.4.12.v20180830]           在org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:558)   [jetty-servlet-9.4.12.v20180830.jar:9.4.12.v20180830]           在org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:917)   [jetty-server-9.4.12.v20180830.jar:9.4.12.v20180830]           在org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:370)   [jetty-servlet-9.4.12.v20180830.jar:9.4.12.v20180830]           在org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1497)   [jetty-webapp-9.4.12.v20180830.jar:9.4.12.v20180830]           在org.eclipse.jetty.maven.plugin.JettyWebAppContext.startWebapp(JettyWebAppContext.java:360)   [jetty-maven-plugin-9.4.12.v20180830.jar:9.4.12.v20180830]           在org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1459)   [jetty-webapp-9.4.12.v20180830.jar:9.4.12.v20180830]           在org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:847)   [jetty-server-9.4.12.v20180830.jar:9.4.12.v20180830]           在org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:287)   [jetty-servlet-9.4.12.v20180830.jar:9.4.12.v20180830]           在org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:545)   [jetty-webapp-9.4.12.v20180830.jar:9.4.12.v20180830]           在org.eclipse.jetty.maven.plugin.JettyWebAppContext.doStart(JettyWebAppContext.java:428)   [jetty-maven-plugin-9.4.12.v20180830.jar:9.4.12.v20180830]           在org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)   [jetty-util-9.4.12.v20180830.jar:9.4.12.v20180830]           在org.eclipse.jetty.maven.plugin.JettyRunMojo.restartWebApp(JettyRunMojo.java:517)   [jetty-maven-plugin-9.4.12.v20180830.jar:9.4.12.v20180830]           在org.eclipse.jetty.maven.plugin.ConsoleScanner.restartWebApp(ConsoleScanner.java:112)   [jetty-maven-plugin-9.4.12.v20180830.jar:9.4.12.v20180830]           在org.eclipse.jetty.maven.plugin.ConsoleScanner.checkSystemInput(ConsoleScanner.java:76)   [jetty-maven-plugin-9.4.12.v20180830.jar:9.4.12.v20180830]           在org.eclipse.jetty.maven.plugin.ConsoleScanner.run(ConsoleScanner.java:46)   [jetty-maven-plugin-9.4.12.v20180830.jar:9.4.12.v20180830]原因:   java.lang.IllegalStateException:无法自省注释   课堂上的方法   com.mycompany.ans.processor.bindings.SpringBootActuatorConfigBindings           在org.springframework.core.type.StandardAnnotationMetadata.getAnnotatedMethods(StandardAnnotationMetadata.java:169)   〜[spring-core-5.1.1.RELEASE.jar:5.1.1.RELEASE]           在org.springframework.context.annotation.ConfigurationClassParser.retrieveBeanMethodMetadata(ConfigurationClassParser.java:392)   〜[spring-context-5.1.1.RELEASE.jar:5.1.1.RELEASE]           在org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:317)   〜[spring-context-5.1.1.RELEASE.jar:5.1.1.RELEASE]           在org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:242)   〜[spring-context-5.1.1.RELEASE.jar:5.1.1.RELEASE]           在org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:589)   〜[spring-context-5.1.1.RELEASE.jar:5.1.1.RELEASE]           ... 29更多原因:java.lang.NoClassDefFoundError:org / springframework / web / servlet / mvc / method / annotation / RequestMappingHandlerMapping           在java.lang.ClassLoader.defineClass1(本机方法)〜[?:1.8.0_202]           在java.lang.ClassLoader.defineClass(ClassLoader.java:763)〜[?:1.8.0_202]           在java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)   〜[?:1.8.0_202]           在java.net.URLClassLoader.defineClass(URLClassLoader.java:468)   〜[?:1.8.0_202]           在java.net.URLClassLoader.access $ 100(URLClassLoader.java:74)〜[?:1.8.0_202]           在java.net.URLClassLoader $ 1.run(URLClassLoader.java:369)〜[?:1.8.0_202]           在java.net.URLClassLoader $ 1.run(URLClassLoader.java:363)〜[?:1.8.0_202]           在java.security.AccessController.doPrivileged(本机方法)〜[?:1.8.0_202]           在java.net.URLClassLoader.findClass(URLClassLoader.java:362)〜[?:1.8.0_202]           在org.eclipse.jetty.webapp.WebAppClassLoader.foundClass(WebAppClassLoader.java:649)   〜[?:?]           在org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:555)   〜[?:?]           在java.lang.ClassLoader.loadClass(ClassLoader.java:357)〜[?:1.8.0_202]           在java.lang.Class.getDeclaredMethods0(本机方法)〜[?:1.8.0_202]           在java.lang.Class.privateGetDeclaredMethods(Class.java:2701)〜[?:1.8.0_202]           在java.lang.Class.getDeclaredMethods(Class.java:1975)〜[?:1.8.0_202]           在org.springframework.core.type.StandardAnnotationMetadata.getAnnotatedMethods(StandardAnnotationMetadata.java:158)   〜[spring-core-5.1.1.RELEASE.jar:5.1.1.RELEASE]           在org.springframework.context.annotation.ConfigurationClassParser.retrieveBeanMethodMetadata(ConfigurationClassParser.java:392)   〜[spring-context-5.1.1.RELEASE.jar:5.1.1.RELEASE]           在org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:317)   〜[spring-context-5.1.1.RELEASE.jar:5.1.1.RELEASE]           在org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:242)   〜[spring-context-5.1.1.RELEASE.jar:5.1.1.RELEASE]           在org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:589)   〜[spring-context-5.1.1.RELEASE.jar:5.1.1.RELEASE]

我想念的地方。

1 个答案:

答案 0 :(得分:1)

如果您检查异常日志:

Caused by: java.lang.IllegalStateException: Failed to introspect annotated methods on class com.mycompany.ans.processor.bindings.SpringBootActuatorConfigBindings
  at org.springframework.core.type.StandardAnnotationMetadata.getAnnotatedMethods(StandardAnnotationMetadata.java:169) ~[spring-core-5.1.1.RELEASE.jar:5.1.1.RELEASE]
  at org.springframework.context.annotation.ConfigurationClassParser.retrieveBeanMethodMetadata(ConfigurationClassParser.java:392) ~[spring-context-5.1.1.RELEASE.jar:5.1.1.RELEASE]
  at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:317) ~[spring-context-5.1.1.RELEASE.jar:5.1.1.RELEASE]
  at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:242) ~[spring-context-5.1.1.RELEASE.jar:5.1.1.RELEASE]
  at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:589) ~[spring-context-5.1.1.RELEASE.jar:5.1.1.RELEASE]
  ... 29 more
Caused by: java.lang.NoClassDefFoundError:
  org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMapping
  at java.lang.ClassLoader.defineClass1(Native Method) ~[?:1.8.0_202]
...

您需要包括Spring Web mvc的依赖项,从该依赖项可以实现RequestMappingHandlerMapping类。这是NoClassDefFoundError的原因。

<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-webmvc</artifactId>
  <version>${org.springframework.version}</version>
</dependency>