Announcement Announcement Module
Collapse
No announcement yet.
ItemWriterAdapter with step scope causes problems Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • ItemWriterAdapter with step scope causes problems

    Hi, I have a item writer that delegates the work to another bean and it also needs some jobparameters in runtime. So because of that I tried to use late binding for the writer with scope step. The problem is that when AbstractMethodInvokingDelegator validates the target object and its methods the targetObject is some Proxy and that proxy does not have the target method declared in ItemWriterAdapter bean configuration. So the AbstractMethodInvokingDelegator.targetClassDeclare sTargetMethod fails to find the targeted method and assertion in afterPropertiesSet fails. If I remove the scope="step" the problem does not exist anymore.

    Am I doing something wrong or something that is not allowed by Spring Batch? Or is this a bug?

    Here's my configuration:

    Code:
    <bean id="params" class="fi...RunParams"
    	scope="step">
    	<property name="dueDate" value="#{jobParameters[dueDate]}" />
    	<property name="runner" value="#{jobParameters[runner]}" />
    </bean>
    
    <bean id="paymentWriter"
    	class="org.springframework.batch.item.adapter.ItemWriterAdapter"
    	scope="step">
    	<property name="targetObject" ref="delegate" />
    	<property name="targetMethod" value="createPayment" />
    </bean>
    
    <bean id="delegate" class="fi...PaymentService"
    	scope="step">
    	<property name="params" ref="params" />
    </bean>

  • #2
    It should work if the createPayment method is defined on one of the interfaces of the target object.

    Comment


    • #3
      Oh, that delegate bean needs to implement interface in which the method is declared. My bean did not implement any interfaces and that is why it was not working. The job is no working after I created simple interface with my targetMethod declared and made targetObject to implement it. The RunParams class needed also interface, because otherwise I got conversion not supported exception in delegate's setParams.

      I should have realized that when I noticed that proxy is used there internally. Is this behaviour by the way specified somewhere in Spring or Spring Batch documentation.
      Last edited by _es; Mar 5th, 2010, 01:32 AM.

      Comment


      • #4
        The proxy is a JDK Proxy (so it can only expose an interface). This is a pretty standard Spring idiom. If you need subclass proxies you can set up StepScope with proxyTargetClass="true" (just include a bean definition as per http://static.springsource.org/sprin...tml#step-scope).

        Comment

        Working...
        X