i am using spring 3, and i have two beans of view scope:
1- Bean1:
2- Bean2:Code:@Component("bean1") @Scope("view") public class Bean1 { @Autowired private Bean2 bean2; }
the view is a custom scope:Code:@Component("bean2") @Scope("view") public class Bean2 { @Autowired private Bean1 bean1; }
and here's the code for the custom view scope:Code:<bean class="org.springframework.beans.factory.config.CustomScopeConfigurer"> <property name="scopes"> <map> <entry key="view"> <bean class="${project.groupId}.utils.ViewScope" /> </entry> </map> </property> </bean>
when opening the page that uses both beans, i get the exception:Code:public class ViewScope implements Scope { @SuppressWarnings("rawtypes") public Object get(String name, ObjectFactory objectFactory) { Map<String, Object> viewMap = FacesContext.getCurrentInstance() .getViewRoot().getViewMap(); if (viewMap.containsKey(name)) { return viewMap.get(name); } else { Object object = objectFactory.getObject(); viewMap.put(name, object); return object; } } public Object remove(String name) { return FacesContext.getCurrentInstance().getViewRoot().getViewMap() .remove(name); } public String getConversationId() { return null; } public void registerDestructionCallback(String name, Runnable callback) { // Not supported } public Object resolveContextualObject(String key) { return null; } }
Code:org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'agencyBean': Requested bean is currently in creation: Is there an unresolvable circular reference? at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:252) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
please advise how to fix this exception.
EDIT: i tried to use the **setter injection** as referenced in the answer here
http://stackoverflow.com/questions/5...lization-order
but it doesn't work too.
1- Bean1:
2- Bean2:Code:@Component("bean1") @Scope("view") public class Bean1 { private Bean2 bean2; @Autowired public void setBean2 (Bean2 bean2) { this.bean2= bean2; } }
but it gives me the exception:Code:@Component("bean2") @Scope("view") public class Bean2 { private Bean1 bean1; @Autowired public void setBean1 (Bean1 bean1) { this.bean1= bean1; } }
Code:org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.myapp.beans.Bean1] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}


Reply With Quote
