As was said in the Luca's comment, you can use a ClassifierCompositeItemWriter which needs a org.springframework.classify.Classifier.
One of the few implementations of the latter is org.springframework.classify.BackToBackPatternClassifier which takes in turn a routerDelegate and a matcherMap.
The routerDelegate is a bean which will have a method annotated with @Classifier. This method will take an Object and return a String. This string will then be matched against the values you declare in your module-context, and call an ItemWriter accordingly.
Here's an example :
<bean class="org.springframework.batch.item.support.ClassifierCompositeItemWriter">
<property name="classifier">
<bean class="org.springframework.classify.BackToBackPatternClassifier">
<property name="routerDelegate">
<bean class="xx.xx.xx.YourClassifier"></bean>
</property>
<property name="matcherMap">
<map>
<entry key="value1">
<bean class="xx.xx.xx.YourItemWriter1></bean>
</entry>
<entry key="value2">
<bean class="xx.xx.xx.YourItemWriter2></bean>
</entry>
</map>
</property>
</bean>
</property>
</bean>
And here's what a Classifier looks like (this one is a Generic classifier using Reflect API to call a method passed as an argument on an object) :
public class GenericClassifier<T> {
private String methodName;
@Classifier
public String classify(T classifiable) {
Method method;
String value = "";
try {
// Get the method with Reflect
method = classifiable.getClass().getMethod(methodName);
// Call the method with Reflect
value= (String) method.invoke(classifiable);
} catch (Exception e) {
// Error management
}
return value;
}
public void setMethodName(String methodName) {
this.methodName = methodName;
}
}
This classifier is used this way, where YourMethod is a public method of the class of the Object to be classified (without the parenthesis) :
<bean class="xx.xx.xx.GenericClassifier">
<property name="methodName" value="YourMethod"></property>
</bean>
The value String returned by the Classifier is then matched with the key of the according entry of the matcherMap.