@EnableAsync annotation metadata was not injected
【问题描述】
@EnableAsync annotation metadata was not injected
spring配置初始化时候报错
nested exception is java.lang.IllegalArgumentException:@EnableAsync annotation metadata was not injected
详情信息如下:
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
【问题原因】
问题出现位置:applicationContext.xml
<!-- 配置component所在的包,自动加载需要管理的Bean --> <context:component-scan base-package="*"></context:component-scan>
在上述配置代码行中,如果使用 * 扫描全部的包会出现此异常,该异常出现的原因为扫描到的包包括框架的内部包,导致包发生同名冲突问题。
【解决方法】
在该配置给出具体的扫描包范围,例如:
<!-- 配置component所在的包,自动加载需要管理的Bean --> <context:component-scan base-package="Data.*,DaoContract,Service,ServiceContract"></context:component-scan>
该问题即可解决!
【博主声明】
本文为站主原创作品,转载请注明出处:http://www.cnblogs.com/7tiny 且在文章页面明显位置给出原文链接。
作者:
作者:
7tiny
Software Development
北京市海淀区 Haidian Area Beijing 100089,P.R.China
郵箱Email : seventiny@foxmail.com
網址Http: http://www.7tiny.com
WeChat: seven-tiny
更多联系方式点我哦~
Best Regard ~