-
circular references
Hi All,
Great work with JavaConfig it has allowed myself and my team to solve a lot of problems with our project that would difficult or impossible to do otherwise.
We are currently in the process of moving all of configuration from spring xml to spring java config but I am getting this error:
Code:
org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'userService': Requested bean is currently in creation: Is there an unresolvable circular reference?
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.beforeSingletonCreation(DefaultSingletonBeanRegistry.java:296)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:215)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:168)
at org.springframework.config.java.context.TypeSafeBeanFactoryUtils.getBean(TypeSafeBeanFactoryUtils.java:74)
at org.springframework.config.java.support.ConfigurationSupport.getBean(ConfigurationSupport.java:76)
at com.symark.smc.service.impl.Config.userGroupService(Config.java:94)
at com.symark.smc.service.impl.Config$$EnhancerByCGLIB$$548db0a3.CGLIB$appUserGroupService$5(<generated>)
at com.symark.smc.service.impl.Config$$EnhancerByCGLIB$$548db0a3$$FastClassByCGLIB$$38617fed.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:167)
at org.springframework.config.java.enhancement.cglib.BeanMethodMethodInterceptor$1.invokeOriginalClass(BeanMethodMethodInterceptor.java:65)
at org.springframework.config.java.core.MethodBeanWrapper.wrapResult(MethodBeanWrapper.java:118)
at org.springframework.config.java.core.StandardBeanMethodProcessor.createNewOrGetCachedSingletonBean(StandardBeanMethodProcessor.java:82)
... 137 more
There are ciruclar references in the configuration but this same configuration worked just fine as spring xml. All I had to do was extend the ApplicationContext and override the AllowRawInjectionDespiteWrapping property and set it to true.
I have done the samething with JavaConfigWebApplicationContext:
Code:
package com.product.web;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.config.java.context.JavaConfigWebApplicationContext;
public class MyWebApplicationContext extends JavaConfigWebApplicationContext {
protected void customizeBeanFactory(DefaultListableBeanFactory beanFactory) {
beanFactory.setAllowRawInjectionDespiteWrapping(true);
}
}
And that is the class I am using in my web.xml, but it is erroring any help would be greatly appreicated.
Thanks,
Mike
-
Hi Mike,
This does look a bit like a bug. To dig deeper, what would help is to have you a) create an issue in JIRA, and b) attach the simplest possible JUnit test case that reproduces the behavior. I'll take it from there.
Thanks,
- Chris
-
Hi Chris,
Thanks for your prompt reply and for all of our efforts on this project.
I have created a JIRA here: bugs.springframework.org/browse/SJC-206
Please let me know if there is anything I can do to help since this issue is critial for our conversion.
Thanks
Mike
-
Mike,
As you'll see in the issue, I've resolved the issue as a duplicate of an earlier related issue (SJC-94). While there are some fundamental limitations here that cannot be worked around, I'd like to make sure your conversion still goes well. If what you see in SJC-94 and the test case I've posted doesn't provide what you need, let me know. There are a number of techniques that should be able to help.
-
Hi Chris,
Thank you again for the quick response and all of your help. I will try the approaches that you suggested in the JIRA (SJC-94) tomorrow morning when I get to work and let you know how it goes.
-Mike
-
Hi Chris,
I just wanted to post and let you know that I was able to get around my circular reference porblems by using the auto wiring as you suggested.
Thanks,
Mike