过度渴望类型匹配的结果 - 考虑使用'getBeanNamesOfType'并关闭'allowEagerInit'标志

时间:2013-08-27 08:55:02

标签: caching transactions aop spring-annotations

org.springframework.beans.factory.BeanCurrentlyInCreationException:创建名称为' org.springframework.cache.annotation.AnnotationCacheOperationSource#0':名称为' org.springframework.cache的Bean时出错。 annotation.AnnotationCacheOperationSource#0'已经作为循环引用的一部分注入其他bean [org.springframework.cache.config.internalCacheAdvisor]作为循环引用的一部分,但最终被包装。这意味着所述其他bean不使用bean的最终版本。这通常是过度渴望类型匹配的结果 - 考虑使用' getBeanNamesOfType'使用' allowEagerInit'例如,旗帜被关闭了。     在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:551)     在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)     at org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:295)     在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)     在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)     在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)     at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626)     在org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)     在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)     at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389)     在org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294)     在org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)     在org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4779)     at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5273)     在org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)     在org.apache.catalina.startup.HostConfig.checkResources(HostConfig.java:1366)     在org.apache.catalina.startup.HostConfig.check(HostConfig.java:1454)     在org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:295)     在org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)     在org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)     在org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1379)     at org.apache.catalina.core.ContainerBase $ ContainerBackgroundProcessor.processChildren(ContainerBase.java:1537)     在org.apache.catalina.core.ContainerBase $ ContainerBackgroundProcessor.processChildren(ContainerBase.java:1547)     在org.apache.catalina.core.ContainerBase $ ContainerBackgroundProcessor.run(ContainerBase.java:1526)     在java.lang.Thread.run(Thread.java:619) 2013年8月27日上午8:33:09 org.apache.catalina.core.StandardContext listenerStart SEVERE:将上下文初始化事件发送到类org.springframework.web.context.ContextLoaderListener的侦听器实例的异常 org.springframework.beans.factory.BeanCurrentlyInCreationException:创建名为' org.springframework.cache.annotation.AnnotationCacheOperationSource#0':Bean名称为' org.springframework.cache.annotation.AnnotationCacheOperationSource的错误#0'已经作为循环引用的一部分注入其他bean [org.springframework.cache.config.internalCacheAdvisor]作为循环引用的一部分,但最终被包装。这意味着所述其他bean不使用bean的最终版本。这通常是过度渴望类型匹配的结果 - 考虑使用' getBeanNamesOfType'使用' allowEagerInit'例如,旗帜被关闭了。     在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:551)     在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)     at org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:295)     在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)     在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)     在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)     at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626)     在org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)     在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)     at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389)     在org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294)     在org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)     在org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4779)     at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5273)     在org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)     在org.apache.catalina.startup.HostConfig.checkResources(HostConfig.java:1366)     在org.apache.catalina.startup.HostConfig.check(HostConfig.java:1454)     在org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:295)     在org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)     在org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)     在org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1379)     at org.apache.catalina.core.ContainerBase $ ContainerBackgroundProcessor.processChildren(ContainerBase.java:1537)     在org.apache.catalina.core.ContainerBase $ ContainerBackgroundProcessor.processChildren(ContainerBase.java:1547)     在org.apache.catalina.core.ContainerBase $ ContainerBackgroundProcessor.run(ContainerBase.java:1526)     在java.lang.Thread.run(Thread.java:619) 0

">

我的application-context.xml

<context:annotation-config />
<!-- Scans within the base package of the application for @Components to 
    configure as beans -->
<context:component-scan base-package="com.voterite.service" />

<aop:aspectj-autoproxy />

<cache:annotation-driven cache-manager="cacheManager" />
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
    <property name="cacheManager" ref="ehcache" />
</bean>
<!-- Ehcache library setup -->
<bean id="ehcache"
    class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
    <property name="configLocation" value="/WEB-INF/ehcache/ehcache.xml" />
</bean>

我正在使用@cachable和aop注释 如何解决BeanCurrentlyInCreationException: 请帮忙

2 个答案:

答案 0 :(得分:4)

我为Validator类中的字段添加了@Lazy注释:

@Autowired **@Lazy** private Service service;

遇到org.springframework.beans.factory.BeanCurrentlyInCreationException时:

“创建名称为'Service'的bean时出错:名称为'Service'的bean已注入到其他bean [Validator] ...”“

”过分渴望的类型匹配结果- 考虑使用getBeanNamesOfType 并关闭allowEagerInit标志”

答案 1 :(得分:1)

default-lazy-init="true"中使用applicationContext.xml,但这只是在开发期间。

对于暂存或测试构建,我们必须删除它,因为它将捕获所有初始bean错误。

我发现我的机器上有一个例外而不是同事,这就是我使用它并恢复工作的原因。

例如,使用顶部beans default-lazy-init="true" xmlns= your xmlns