@EnableAsync annotation metadata was not injected Spring容器启动后访问Servlet报错
@EnableAsync annotation metadata was not injected
在初始化spring事务部分碰到该错误, 详细错误信息如下:
- 警告: Exception encountered during context initialization - cancelling refresh attempt
- 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
- at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1119)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1014)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
- at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
- at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
- at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
- at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
- at org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:220)
- at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:615)
- at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:465)
- at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:434)
- at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
- at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
- at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:782)
- at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:424)
- at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:774)
- at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:249)
- at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1242)
- at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:717)
- at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:494)
- at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
- at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:95)
- at org.eclipse.jetty.server.Server.doStart(Server.java:282)
- at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
- at net.sourceforge.eclipsejetty.starter.embedded.JettyEmbeddedAdapter.start(JettyEmbeddedAdapter.java:67)
- at net.sourceforge.eclipsejetty.starter.common.AbstractJettyLauncherMain.launch(AbstractJettyLauncherMain.java:84)
- at net.sourceforge.eclipsejetty.starter.embedded.JettyEmbeddedLauncherMain.main(JettyEmbeddedLauncherMain.java:42)
- 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
- at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
- at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
- ... 28 more
- Caused by: java.lang.IllegalArgumentException: @EnableAsync annotation metadata was not injected
- at org.springframework.util.Assert.notNull(Assert.java:112)
- at org.springframework.scheduling.annotation.ProxyAsyncConfiguration.asyncAdvisor(ProxyAsyncConfiguration.java:45)
- at org.springframework.scheduling.annotation.ProxyAsyncConfiguration
EnhancerBySpringCGLIBEnhancerBySpringCGLIB82eb591.CGLIB$asyncAdvisor$0(<generated>)
- at org.springframework.scheduling.annotation.ProxyAsyncConfiguration
EnhancerBySpringCGLIBEnhancerBySpringCGLIB82eb591FastClassBySpringCGLIBFastClassBySpringCGLIBed8c37b9.invoke(<generated>)
- at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
- at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:309)
- at org.springframework.scheduling.annotation.ProxyAsyncConfiguration
EnhancerBySpringCGLIBEnhancerBySpringCGLIB82eb591.asyncAdvisor(<generated>)
- at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
- at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
- at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
- at java.lang.reflect.Method.invoke(Method.java:606)
- at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
- ... 29 more
- 十二月 16, 2015 11:42:21 下午 org.springframework.web.context.ContextLoader initWebApplicationContext
- 严重: Context initialization failed
- 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
- at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1119)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1014)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
- at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
- at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
- at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
- at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
- at org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:220)
- at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:615)
- at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:465)
- at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:434)
- at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
- at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
- at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:782)
- at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:424)
- at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:774)
- at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:249)
- at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1242)
- at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:717)
- at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:494)
- at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
- at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:95)
- at org.eclipse.jetty.server.Server.doStart(Server.java:282)
- at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
- at net.sourceforge.eclipsejetty.starter.embedded.JettyEmbeddedAdapter.start(JettyEmbeddedAdapter.java:67)
- at net.sourceforge.eclipsejetty.starter.common.AbstractJettyLauncherMain.launch(AbstractJettyLauncherMain.java:84)
- at net.sourceforge.eclipsejetty.starter.embedded.JettyEmbeddedLauncherMain.main(JettyEmbeddedLauncherMain.java:42)
- 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
- at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
- at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
- ... 28 more
- Caused by: java.lang.IllegalArgumentException: @EnableAsync annotation metadata was not injected
- at org.springframework.util.Assert.notNull(Assert.java:112)
- at org.springframework.scheduling.annotation.ProxyAsyncConfiguration.asyncAdvisor(ProxyAsyncConfiguration.java:45)
- at org.springframework.scheduling.annotation.ProxyAsyncConfiguration
EnhancerBySpringCGLIBEnhancerBySpringCGLIB82eb591.CGLIB$asyncAdvisor$0(<generated>)
- at org.springframework.scheduling.annotation.ProxyAsyncConfiguration
EnhancerBySpringCGLIBEnhancerBySpringCGLIB82eb591FastClassBySpringCGLIBFastClassBySpringCGLIBed8c37b9.invoke(<generated>)
- at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
- at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:309)
- at org.springframework.scheduling.annotation.ProxyAsyncConfiguration
EnhancerBySpringCGLIBEnhancerBySpringCGLIB82eb591.asyncAdvisor(<generated>)
- at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
- at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
- at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
- at java.lang.reflect.Method.invoke(Method.java:606)
- at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
- ... 29 more
在spring的配置文件applicationContext.xml中, 配置包扫描器时, 使用了*, 想扫描所有的包; 而这种方式有可能扫描到spring自带的包, 造成错误(自我理解, 不对的话求教育)
改动前:
- <!-- 包扫描器 -->
- <context:component-scan base-package="*"/>
- <!-- 包扫描器 -->
- <context:component-scan base-package="com.git.*"/>
posted on 2018-04-25 14:37 David_Deng 阅读(1471) 评论(0) 编辑 收藏 举报