Announcement Announcement Module
Collapse
No announcement yet.
Can't declare bean inline of tasklet? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Can't declare bean inline of tasklet?

    This is what I want to write:

    Code:
    <job id="myJob" xmlns="http://www.springframework.org/schema/batch">  
     <step id="myStep">
      <tasklet>
       <bean class="com.company.mytasklet">
        <property name="foo" value="bar"/>
       </bean >
      </tasklet>
     </step>
    </job>
    But the XML validater won't let me. You can see the xsd for this at

    http://www.springframework.org/schem...-batch-2.1.xsd

    I am never going to reuse the inner bean again. I want to define it inline. In the tasklet's XSD I see:

    HTML Code:
    <xsd:element ref="beans:bean" minOccurs="0" maxOccurs="1" />
    But I can't make it validate. Instead I have to write the cheap hack of:

    Code:
    <job id="myJob" xmlns="http://www.springframework.org/schema/batch">  
     <step id="myStep">
      <tasklet ref="myTasklet"/>
     </step>
    </job>
    
    <bean class="com.company.mytasklet" id="myTasklet">
        <property name="foo" value="bar"/>
    </bean >
    What am I missing?

  • #2
    Below should help you.


    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:batch="http://www.springframework.org/schema/batch"
    	xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
    	xmlns:task="http://www.springframework.org/schema/task" xmlns:tx="http://www.springframework.org/schema/tx"
    	xmlns:util="http://www.springframework.org/schema/util"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    		http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd
    		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
    		http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
    		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
    		http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd">
    
    <import resource="./launcher-beans.xml"/>	
    
    	<batch:job id="templateJob" job-repository="jobRepository">
    
    		<batch:step id="fileStep">
    			<batch:tasklet >
    				<bean class=".............TemplateTasklet" scope="step">
    				</bean>
    			</batch:tasklet>
    
    		</batch:step>
    	<batch:listeners>
    	<batch:listener>
    	<bean class="......Listener">
    				</bean>
    	</batch:listener>
    	</batch:listeners>
    	</batch:job>
    
    		
    </beans>

    Comment


    • #3
      Great thanks!

      Comment

      Working...
      X