spring批处理中的skippable-exception-classes只跳过一行

时间:2017-02-10 17:53:37

标签: spring spring-data-jpa spring-batch

我是春季批处理新手,例如csv文件

<?xml version="1.0"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
           xmlns:s="library://ns.adobe.com/flex/spark">
<fx:Script><![CDATA[
    import mx.collections.ArrayCollection;
    [Bindable]
    private var myDataProvider:ArrayCollection = new ArrayCollection([
        {data:1, label:"One", desc:"Here is a toolTip description of the item One"},
        {data:2, label:"Two", desc:"Here is a toolTip description of the item Two"},
        {data:3, label:"Three", desc:"Here is a toolTip description of the item Three"},
        {data:4, label:"Four", desc:"Here is a toolTip description of the item Four"},
        {data:5, label:"Five", desc:"Here is a toolTip description of the item Five"}
    ]);
    ]]></fx:Script>
    <s:List dataProvider="{myDataProvider}">
        <s:itemRenderer>
            <fx:Component>
                <s:ItemRenderer>
                    <fx:Script><![CDATA[
                        override public function set data(value:Object):void
                        {
                            super.data = value;
                        }
                        [Bindable]
                        private function getToolTip():String
                        {
                            return data.desc;
                        }
                        ]]></fx:Script>
                    <s:Label text="{data.label}" toolTip="{getToolTip()}" width="100%"/>
                </s:ItemRenderer>
            </fx:Component>
        </s:itemRenderer>
    </s:List>
</s:Application>

这是我的格式

如果名称存在的雇主mysql将抛出DataIntegrityViolationException

所以我添加了

Employee   Name Id age year
Department DeptName deptId desc
Department DeptName deptId desc
Employee   Name Id age year
Department DeptName deptId desc
Department DeptName deptId desc

因此,这将跳过整个单位相应的雇主和部门记录

即使Employee存在并且抛出此异常

,我还要做什么

然后继续部门。

1 个答案:

答案 0 :(得分:0)

我建议使用项目分类器

public class ItemTypeClassifier {
    @Classifier
    public String classify(Item item) {
        return item.getType();// returns "Employee", "Department"
    }
}

然后是一个带有两个不同项目编写器的路由器实现,一个用于员工,一个用于部门。

<bean id="classifier"  class="org.springframework.batch.classify.BackToBackPatternClassifier">
    <property name="routerDelegate">
        <bean class="ItemTypeClassifier" />
    </property>
    <property name="matcherMap">
        <map>
            <entry key="Employee" value-ref="emplyeeItemWriter" />
            <entry key="Department" value-ref="departmentItemWriter" />
        </map>
    </property>
</bean>

然后

<bean id="ItemWriter" class="org.springframework.batch.item.support.ClassifierCompositeItemWriter">
    <property name="classifier" ref="classifier" />
</bean>

现在您有两个不同的编写器,您可以通过为它们定义两个单独的可跳过异常配置来在您的作业中运行两个步骤。