Announcement Announcement Module
Collapse
No announcement yet.
only before is getting called in advice Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • only before is getting called in advice

    Hi,
    I was just playing around with spring AOP and, i am newbie as far as AOP is concerned. for the below advice, only "before" is getting called.Any idea what's wrong? or is it necessary to have different advice class for each advice.



    <bean id="testDAO"
    class="org.springframework.aop.framework.ProxyFact oryBean">
    <property name="proxyInterfaces">
    <value>com.test.dao.ITestDAO</value>
    </property>
    <property name="target">
    <ref local="TestDAOImpl"/>
    </property>
    <property name="interceptorNames">
    <list>
    <value>Logger</value>
    </list>
    </property>
    </bean>

    <!-- Advisor pointcut definition for before advice -->
    <bean id="Logger"
    class="org.springframework.aop.support.RegexpMetho dPointcutAdvisor">
    <property name="advice">
    <ref local="LoggerAdvisor"/>
    </property>
    <property name="pattern">
    <value>.*</value>
    </property>
    </bean>


    <!-- Advice classes -->
    <bean id="LoggerAdvisor"
    class="com.test.logger.CommonLoggerAdvice"/>


    public class CommonLoggerAdvice implements MethodBeforeAdvice,AfterReturningAdvice,ThrowsAdvi ce {

    public void before(Method m, Object[] args, Object target) throws Throwable {
    System.out.println("Class Name : " + this.getClass().getName() +
    "Method Executed : " + m.getName() );
    }

    public void afterReturning(Object object,Method m,Object[] args,Object target) throws Throwable {
    System.out.println(
    "Hello world! (by " +
    this.getClass().getName() +
    ")");
    }

    public void afterThrowing(Exception e) throws Throwable {
    e.printStackTrace();
    }

    }

    Thanks

  • #2
    The AOP framework doesn't expect you to implement multiple AOP interfaces in the one object. If one object needs to handle before, after and throws, you should really code it as an around advice (MethodInterceptor) and put all the behaviour in a single method.

    Rgds
    Rod

    Comment


    • #3
      Thanks Rod.

      Comment

      Working...
      X