babygetoboy
babygetoboy

Reputation: 13

Spring Batch Monitoring

I am having a really tough time with this for some reason and would love some help. All I really need to do it access when Spring Batch is failing and grab the data. I have tried to implement Spring Batch Admin but that didn't seem to work so I was going to write my own class, but I can not seem to get it to work. Anyone have any help? Thanks in advance.

Upvotes: 0

Views: 856

Answers (1)

Surya
Surya

Reputation: 350

You can use ItemListenerSupport. Override onRead Error(), onProcessError () and onWriteError(), etc., methods. For e.g., on error in your writer, onWriteError() method will be invoked and you will get exception and list of objects.

public class ItemFailureLoggerListener extends ItemListenerSupport {

    private static Log logger = LogFactory.getLog("item.error");

    public void onReadError(Exception ex) {
        logger.error("Encountered error on read", e);
    }

    public void onWriteError(Exception ex, Object item) {
        logger.error("Encountered error on write", ex);
    }

}

Having implemented this listener it must be registered with the step:

<step id="simpleStep">
    ...
    <listeners>
        <listener>
            <bean class="org.example...ItemFailureLoggerListener"/>
        </listener>
    </listeners>
</step>

Source: http://docs.spring.io/spring-batch/reference/html/patterns.html

Upvotes: 1

Related Questions