I want to declare two beans and instantiate them using Spring dependency injection?
<bean id='sessionFactory' class='SessionFactoryImpl'> <property name='entityInterceptor' ref='entityInterceptor'/> </bean> <bean id='entityInterceptor' class='EntityInterceptorImpl'> <property name='sessionFactory' ref='sessionFactory'/> </bean>
But Spring throws an exception saying ‘FactoryBean which is currently in creation returned null from getObject’
Why is inter-dependent bean wiring not working here? Should i specify defferred property binding anywhere?
Unfortunately the way container initialization works in Spring, a bean can only be injected in another bean once it is fully initialized. In your case you have a circular dependency that prevents either bean to be initialized because they depend on each other. To get around this you can implement BeanFactoryAware in one of the beans and obtain the reference to the other bean using beanFactory.getBean(‘beanName’).