Announcement Announcement Module
Collapse
No announcement yet.
ItemWriters Dynamically Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • ItemWriters Dynamically

    How to create ItemWriter pool with n itemwriters where n being set dynamically through job parameters.

  • #2
    Anish,

    Spring factory-bean/factory-method would be one of the things you can try .

    Sample Code :
    Code:
    public class ReaderFactory implements ApplicationContextAware, FactoryBean  {
    
    	protected ApplicationContext applicationContext;
    	protected String reader;
    
    	public void setReader( String reader)
    	{
    		this.reader = reader;
    	}
    
    	public Class getObjectType() {
    		return AbstractItemCountingItemStreamItemReader.class; 
    	}
    
    	public boolean isSingleton() {
    		return false;
    	}
    
    	public Object getObject() {
    
    		
    		if (reader != null) {
    			System.out.println("READER"+reader);
    			Object reader1 = applicationContext.getBean(reader);
    			
    			return reader1;
    		}
    		else return null;	
    	}
    
    	public void setApplicationContext(ApplicationContext applicationContext)
    			throws BeansException {
    		this.applicationContext = applicationContext;
    		
    	}
    
    }

    XML CONFIG FILE:

    Code:
    <bean id="EDIJob" parent="simpleJob" >
    		<property name="steps"  >
    			<bean id="step1" parent="simpleStep" >
    				<property name="streams" >
    					<list>
    					   										               
                                            </list>
    
    				</property>
    				
    				<property name="itemReader" ref="reader" />
    				<property name="itemWriter" ref="writer" />
    
    
    				
    				
    			</bean>
    		</property>
    	</bean>
    
    
    
    <bean id="reader" class="com.abcbs.EDI837.common.ReaderFactory"  >
    	
    	<property name="reader" value="#{jobParameters['reader.name']}"/>		
    	</bean>

    Comment

    Working...
    X