spring配置初始化時候報錯java
nested exception is java.lang.IllegalArgumentException:@EnableAsync annotation metadata was not injectedweb
詳情信息以下:spring
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 app
<!-- 配置component所在的包,自動加載須要管理的Bean --> <context:component-scan base-package="*"></context:component-scan>
在上述配置代碼行中,若是使用 * 掃描所有的包會出現此異常,該異常出現的緣由爲掃描到的包包括框架的內部包,致使包發生同名衝突問題。
在該配置給出具體的掃描包範圍,例如:框架
<!-- 配置component所在的包,自動加載須要管理的Bean --> <context:component-scan base-package="Data.*,DaoContract,Service,ServiceContract"></context:component-scan>
該問題便可解決!