@EnableAsync annotation metadata was not injected Spring容器启动后访问Servlet报错

@EnableAsync annotation metadata was not injected

2015年12月20日 20:06:54

  • 7570

在初始化spring事务部分碰到该错误, 详细错误信息如下:

[plain] view plain copy

  1. 警告: Exception encountered during context initialization - cancelling refresh attempt
  2. org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘org.springframework.context.annotation.internalAsyncAnnotationProcessor‘ defined in org.springframework.scheduling.annotation.ProxyAsyncConfiguration: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.scheduling.annotation.AsyncAnnotationBeanPostProcessor]: Factory method ‘asyncAdvisor‘ threw exception; nested exception is java.lang.IllegalArgumentException: @EnableAsync annotation metadata was not injected
  3. at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)
  4. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1119)
  5. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1014)
  6. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
  7. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
  8. at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
  9. at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
  10. at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
  11. at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
  12. at org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:220)
  13. at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:615)
  14. at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:465)
  15. at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:434)
  16. at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
  17. at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
  18. at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:782)
  19. at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:424)
  20. at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:774)
  21. at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:249)
  22. at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1242)
  23. at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:717)
  24. at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:494)
  25. at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
  26. at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:95)
  27. at org.eclipse.jetty.server.Server.doStart(Server.java:282)
  28. at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
  29. at net.sourceforge.eclipsejetty.starter.embedded.JettyEmbeddedAdapter.start(JettyEmbeddedAdapter.java:67)
  30. at net.sourceforge.eclipsejetty.starter.common.AbstractJettyLauncherMain.launch(AbstractJettyLauncherMain.java:84)
  31. at net.sourceforge.eclipsejetty.starter.embedded.JettyEmbeddedLauncherMain.main(JettyEmbeddedLauncherMain.java:42)
  32. Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.scheduling.annotation.AsyncAnnotationBeanPostProcessor]: Factory method ‘asyncAdvisor‘ threw exception; nested exception is java.lang.IllegalArgumentException: @EnableAsync annotation metadata was not injected
  33. at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
  34. at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
  35. ... 28 more
  36. Caused by: java.lang.IllegalArgumentException: @EnableAsync annotation metadata was not injected
  37. at org.springframework.util.Assert.notNull(Assert.java:112)
  38. at org.springframework.scheduling.annotation.ProxyAsyncConfiguration.asyncAdvisor(ProxyAsyncConfiguration.java:45)
  39. at org.springframework.scheduling.annotation.ProxyAsyncConfiguration

    EnhancerBySpringCGLIBEnhancerBySpringCGLIB

    82eb591.CGLIB$asyncAdvisor$0(<generated>)

  40. at org.springframework.scheduling.annotation.ProxyAsyncConfiguration

    EnhancerBySpringCGLIBEnhancerBySpringCGLIB

    82eb591

    FastClassBySpringCGLIBFastClassBySpringCGLIB

    ed8c37b9.invoke(<generated>)

  41. at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
  42. at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:309)
  43. at org.springframework.scheduling.annotation.ProxyAsyncConfiguration

    EnhancerBySpringCGLIBEnhancerBySpringCGLIB

    82eb591.asyncAdvisor(<generated>)

  44. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  45. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
  46. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  47. at java.lang.reflect.Method.invoke(Method.java:606)
  48. at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
  49. ... 29 more
  50. 十二月 16, 2015 11:42:21 下午 org.springframework.web.context.ContextLoader initWebApplicationContext
  51. 严重: Context initialization failed
  52. org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘org.springframework.context.annotation.internalAsyncAnnotationProcessor‘ defined in org.springframework.scheduling.annotation.ProxyAsyncConfiguration: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.scheduling.annotation.AsyncAnnotationBeanPostProcessor]: Factory method ‘asyncAdvisor‘ threw exception; nested exception is java.lang.IllegalArgumentException: @EnableAsync annotation metadata was not injected
  53. at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)
  54. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1119)
  55. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1014)
  56. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
  57. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
  58. at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
  59. at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
  60. at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
  61. at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
  62. at org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:220)
  63. at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:615)
  64. at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:465)
  65. at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:434)
  66. at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
  67. at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
  68. at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:782)
  69. at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:424)
  70. at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:774)
  71. at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:249)
  72. at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1242)
  73. at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:717)
  74. at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:494)
  75. at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
  76. at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:95)
  77. at org.eclipse.jetty.server.Server.doStart(Server.java:282)
  78. at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
  79. at net.sourceforge.eclipsejetty.starter.embedded.JettyEmbeddedAdapter.start(JettyEmbeddedAdapter.java:67)
  80. at net.sourceforge.eclipsejetty.starter.common.AbstractJettyLauncherMain.launch(AbstractJettyLauncherMain.java:84)
  81. at net.sourceforge.eclipsejetty.starter.embedded.JettyEmbeddedLauncherMain.main(JettyEmbeddedLauncherMain.java:42)
  82. Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.scheduling.annotation.AsyncAnnotationBeanPostProcessor]: Factory method ‘asyncAdvisor‘ threw exception; nested exception is java.lang.IllegalArgumentException: @EnableAsync annotation metadata was not injected
  83. at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
  84. at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
  85. ... 28 more
  86. Caused by: java.lang.IllegalArgumentException: @EnableAsync annotation metadata was not injected
  87. at org.springframework.util.Assert.notNull(Assert.java:112)
  88. at org.springframework.scheduling.annotation.ProxyAsyncConfiguration.asyncAdvisor(ProxyAsyncConfiguration.java:45)
  89. at org.springframework.scheduling.annotation.ProxyAsyncConfiguration

    EnhancerBySpringCGLIBEnhancerBySpringCGLIB

    82eb591.CGLIB$asyncAdvisor$0(<generated>)

  90. at org.springframework.scheduling.annotation.ProxyAsyncConfiguration

    EnhancerBySpringCGLIBEnhancerBySpringCGLIB

    82eb591

    FastClassBySpringCGLIBFastClassBySpringCGLIB

    ed8c37b9.invoke(<generated>)

  91. at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
  92. at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:309)
  93. at org.springframework.scheduling.annotation.ProxyAsyncConfiguration

    EnhancerBySpringCGLIBEnhancerBySpringCGLIB

    82eb591.asyncAdvisor(<generated>)

  94. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  95. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
  96. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  97. at java.lang.reflect.Method.invoke(Method.java:606)
  98. at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
  99. ... 29 more

错误原因:

在spring的配置文件applicationContext.xml中, 配置包扫描器时, 使用了*, 想扫描所有的包; 而这种方式有可能扫描到spring自带的包, 造成错误(自我理解, 不对的话求教育)

改动前:

[html] view plain copy

  1. <!-- 包扫描器 -->
  2. <context:component-scan base-package="*"/>

改动后(具体指定了要扫描的包):

[html] view plain copy

  1. <!-- 包扫描器 -->
  2. <context:component-scan base-package="com.git.*"/>

原文地址:https://www.cnblogs.com/javaboy2018/p/8944568.html

时间: 2024-10-10 14:34:33

@EnableAsync annotation metadata was not injected Spring容器启动后访问Servlet报错的相关文章

Spring容器启动后注入service到Servlet并自动执行

通常做法是定义一个Servlet,并在web.xml中配置Servlet的启动顺序<load-on-startup>的值在DispatcherServlet之后.但这样做的缺点是在Servlet中无法使用Spring的依赖注入功能,只能使用WebApplicationContext的getBean()方法获取bean. 找到的解决办法如下: 1.自定义一个用于代理启动Servlet的类DelegatingServletProxy: package cn.edu.swu.oa.common.ut

@EnableAsync annotation metadata was not injected

今天将老的项目放在Myeclipse2015中运行时,报错了. 错误原因: 在spring的配置文件applicationContext.xml中, 配置包扫描器时, 使用了*, 想扫描所有的包; 而这种方式有可能扫描到spring自带的包, 造成错误(自我理解, 不对的话求教育) 改动前: <!-- 包扫描器 --> <context:component-scan base-package="*"/> 改动后 : <!-- 包扫描器 --> <

spring容器启动之我见

spring容器启动之我见. 本人也是自己看看源码,然后方便以后自己记忆和理解,故写此文章,如果有什么错的地方还请大家提出. 针对于tomcat做服务器的项目,我们首先看的就是web.xml文件,spring容器启动去加载监听器 看如下代码:其监听器使用spring api中的类ContextLoaderListener <context-param> <param-name>contextConfigLocation</param-name> <param-va

菜鸟调错(四)——Spring与DWR集成,配置文件报错

背景简介: 该项目是市信用办的一个系统,之前好像是一个石家庄的公司负责的.我属于是半路接手.拿到源码后,根据他们给的简(shao)单(de)明(ke)了(lian)的说明把项目搭起来.结果可想而知,项目文件一片红.于是就开始解决这些错误,好在很多错误都是类似的.经过一番捣鼓,大部分的错误都解决了,有一个Spring跟DWR集成配置的错误,错误信息如下: Multiple annotations found at this line: - schema_reference.4: Failed to

Bug集锦-Spring Cloud Feign调用其它接口报错

问题描述 Spring Cloud Feign调用其它服务报错,错误提示如下:Failed to instantiate [java.util.List]: Specified class is an interface. 解决方案 通过查询一些资料,得到的结论,是定义接口传递的参数时,没有用@RequestBody修饰,查看定义接口有用@RequestBogy修饰,Feign的接口实现里没有用@RequestBody修饰,添加后问题就解决了,以后还是要仔细看待每个问题. 原文地址:https:

Spring Boot 2.1.7 启动项目失败,报错: &quot;Failed to configure a DataSource: &#39;url&#39; attribute is not specified and no embedded datasource could be configured.&quot;

一开始按照网上的很多解决办法是: 启动类头部声明@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class}),但是这样会排除掉我自己的数据库配置, 检查了很多地方都没发现问题在哪里,最后自己猜想不论怎么修改application.yml文件,都不生效,是不是因为这个配置文件就没有被加载到? 带着这个想法我就去网上搜了一下问题,有个问题看到了target目录的作用,就去想了一下是不是application.yml文件没有被

spring容器启动原理分析1

在项目的web.xml中配置 1 <listener> 2 <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 3 </listener> 此配置为spring容器加载入口,因为其javax.servlet.ServletContextListener接口. 下面代码为ServletContextListener的源码: public i

spring容器启动的加载过程

使用spring,我们在web.xml都会配置ContextLoaderListener <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> public class ContextLoaderListener extends ContextLoader implements Servle

spring容器启动的加载过程(二)

第六步: public abstract class AbstractApplicationContext extends DefaultResourceLoader implements ConfigurableApplicationContext, DisposableBean { protected ConfigurableListableBeanFactory obtainFreshBeanFactory() { refreshBeanFactory();//具体实现调用子类容器的ref