Results 1 to 5 of 5

Thread: problem in setting up circular reference

  1. #1
    Join Date
    Apr 2007
    Posts
    27

    Default problem in setting up circular reference

    I am unable to figure out the problem in this application context setting,

    Code:
    <!-- Default batch job configuration set -->
    	<bean id="defaultService" class="com.gn.rb.batch.framework.DefaultService"/>
    	<bean id="defaultBatchJob" class="com.gn.rb.batch.framework.DefaultBatchJob">
    		<property name="serviceName" value="Default" />
    		<property name="batchJobShutdownHook" ref="defaultBatchJobShutdownHook"/>
    		<property name="service" ref="defaultService" />
    	</bean>
    	<bean id="defaultBatchJobShutdownHook" class="com.gn.rb.batch.framework.DefaultBatchJobShutdownHook">
    		<property name="batchJob" ref="defaultBatchJob"/>
    	</bean>
    <!--  -->

    I am getting an error,
    Error creating bean with name 'defaultBatchJob': Bean with name 'defaultBatchJob' has been injected into other beans [defaultBatchJobShutdownHook] in its raw version as part of a circular reference, but has eventually been wrapped (for example as part of auto-proxy creation). This means that said other beans do not use the final version of the bean. This is often the result of over-eager type matching - consider using 'getBeanNamesOfType' with the 'allowEagerInit' flag turned off, for example.

    Please advice.

  2. #2
    Join Date
    Feb 2005
    Posts
    217

    Default

    Bean with name 'defaultBatchJob' has been injected into other beans [defaultBatchJobShutdownHook]
    I'm not sure how much more spelled out the error message can get. What you have is A requiring B in its settings. However B also requires A. You can't do that.

    The fix is to figure out if A needs B or if B needs A. In your case I'm not sure why the defaultBatchJobShutdownHook needs to know about the defaultBatchJob.

  3. #3

    Default Refrence answer to circular dependencies

    Circular dependencies

    If you are using predominantly constructor injection it is possible to write and configure your classes and
    beans such that an unresolvable circular dependency scenario is created.
    Consider the scenario where you have class A, which requires an instance of class B to be provided via
    constructor injection, and class B, which requires an instance of class A to be provided via constructor
    injection. If you configure beans for classes A and B to be injected into each other, the Spring IoC
    container will detect this circular reference at runtime, and throw a
    BeanCurrentlyInCreationException.
    One possible solution to this issue is to edit the source code of some of your classes to be configured via
    setters instead of via constructors. Another solution is not to use constructor injection and stick to setter
    injection only.
    mmmm, I think I will order a cup of coffee in this beautiful spring day

  4. #4
    Join Date
    Apr 2007
    Posts
    27

    Default

    As always thanks for the lightning fast response. Taking the first advice I have changed the removed the circular relationship. Now I have a different problem.
    I want to make the batch job classes serializable since I want to persists them as objects to a database.
    Strangely, the moment I add "implements Serializable" to the batch job class
    the application fails with this message,
    Code:
    Failed to convert property value of type [$Proxy1] to required type [com.generali.ruby.batch.framework.AbstractBatchJob] for property 'remittanceShareBatchJob'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy1] to required type [com.generali.ruby.batch.framework.AbstractBatchJob] for property 'remittanceShareBatchJob': no matching editors or conversion strategy found
    It seems making a spring instantiated class serializable has some side effects and needs to handled differently.

    Please advice.

  5. #5
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,425

    Default

    I guess you are using proxies somewhere (e.g. TransactionProxyFactoryBean) and you aren't programming to interfaces. You'll either need to add proxyTargetClass="true" or program to interfaces.
    http://www.springframework.org/docs/...l#aop-proxying

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •