Announcement Announcement Module
No announcement yet.
Configured AOPs not working in Spring Batch Samples Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Configured AOPs not working in Spring Batch Samples

    Hi All,

    Am new to Spring Batch and even Spring AOP.

    I am executing the FootBall Sample and its working as expected. But the AOPs that were configured for logging weren't working.

    <!--  AOP Configurations -->
    <bean id="logAdvice" class="org.springframework.batch.sample.common.LogAdvice" />
    	<bean id="eventAdvice" class="org.springframework.batch.sample.jmx.StepExecutionApplicationEventAdvice" />
    		<aop:aspect id="moduleLogging" ref="logAdvice">
    				pointcut="execution( * org.springframework.batch.item.ItemWriter+.write(Object)) and args(item)"
    				method="doStronglyTypedLogging" />
    		<aop:aspect ref="eventAdvice">
    				pointcut="execution( * org.springframework.batch..Step+.execute(..)) and args(stepExecution)"
    				method="before" />
    				pointcut="execution( * org.springframework.batch..Step+.execute(..)) and args(stepExecution)"
    				method="after" />
    			<aop:after-throwing throwing="t" 
    				pointcut="execution( * org.springframework.batch..Step+.execute(..)) and args(stepExecution)"
    				method="onError" />
    The above code is as provided in the samples. I modified LogAdvice class to use Log4j instead of Commons Logging.

    When ran the tests, doStronglyTypedLogging in LogAdvice is never called.

    For the other aop aspect, before and after methods for StepExecutionApplicationEventAdvice is invoked and able to log a message to console. But what happens after the below code is invoked ?
    applicationEventPublisher.publishEvent(new SimpleMessageApplicationEvent(source, message));
    When & How will the toString() method be called on SimpleMessageApplicationEvent ?

    Am I missing any other configurations thats causing problem with aop logging.. Please advice.

    Madan Narra

  • #2
    I think the point cut in the logging aspect is wrong - the signature of ItemWriter.write() is incorrect. Try write(..) instead of write(Object).

    The event publisher advice publishes an ApplicationEvent - there are no listeners registered by default, so it's just there as a demo of the feature. ApplicationListener is a Spring Framework feature, so ask about it in the main forum if you want to use it.
    Last edited by Dave Syer; Apr 26th, 2011, 04:09 AM.


    • #3
      Hi Dave,

      Thanks for the reply.

      Changing write(Object) to write(..) fixed the issue.

      Also, I got the listener setup to listen for the events.

      Below is the configuration for others who would like to setup an listener to capture the published events.

      Modify launch-context.xml and add the below code
      <bean id="simpleMessageListener" class="org.springframework.batch.sample.jmx.SimpleMessageListener"/>
      And corresponding
      package org.springframework.batch.sample.jmx;
      import org.springframework.context.ApplicationEvent;
      import org.springframework.context.ApplicationListener;
      public class SimpleMessageListener implements ApplicationListener {
      	public void onApplicationEvent(ApplicationEvent event) {
      		if(event instanceof SimpleMessageApplicationEvent) {
      			System.out.println("Message Received :: "+((SimpleMessageApplicationEvent)event).toString());
      Madan Narra