Results 1 to 3 of 3

Thread: only before is getting called in advice

Hybrid View

  1. #1
    Join Date
    Aug 2004
    Posts
    15

    Default 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. #2
    Join Date
    Aug 2004
    Location
    San Mateo, CA
    Posts
    1,265

    Default

    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

  3. #3
    Join Date
    Aug 2004
    Posts
    15

    Default

    Thanks Rod.

Similar Threads

  1. handleInvalidSubmit called, why?
    By sulam in forum Web
    Replies: 9
    Last Post: Feb 2nd, 2007, 03:11 AM
  2. After advice design question
    By drc in forum AOP
    Replies: 2
    Last Post: Sep 29th, 2005, 11:14 PM
  3. Replies: 5
    Last Post: Mar 28th, 2005, 08:41 AM
  4. Replies: 9
    Last Post: Dec 6th, 2004, 04:05 PM
  5. indirectly called method not intercepted
    By springtester in forum AOP
    Replies: 1
    Last Post: Sep 1st, 2004, 06:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •