0

I am new to spring.I know that AfterAdvice will cause the after method to execute whether target method completes or exits with exception, but i am not able to find out any example for it.

As AfterAdvice is a marker interface, I don't know which method i need to define in it's implementation class.

Thanks,

Xstian
  • 8,184
  • 10
  • 42
  • 72
Manish
  • 1,274
  • 3
  • 22
  • 59

1 Answers1

0

You do not have to implement those interfaces directly. Instead, you use either

  1. Use @After annotation to mark the method you want to it to be called.
  2. Use spring xml bean configuration aop:advice to declare an after advice method

However, if you choose to use ProxyFactoryBean

As you indicate that you want to use ProxyFactoryBean, you can declare the xml like this

<bean id="interceptor"
   class="yourimplementation">
</bean>
<bean id="setterAdvisor"
   class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
    <property name="advice">
        <ref bean="interceptor"/>
    </property>
    <property name="patterns">
        <list>
            <value>.*set.*</value>
        </list>
    </property>
</bean>
<bean id="person"
    class="org.springframework.aop.framework.ProxyFactoryBean">
    <property name="proxyInterfaces" value="com.mycompany.Person"/>
    <property name="target" ref="personTarget"/>
    <property name="interceptorNames">
        <list>
            <value>setterAdvisor</value>
        </list>
    </property>
</bean>

For the java implementation, there is no use to implement Advice interface. You should either implement ThrowingAdvice or AfterReturningAdvice. Refer to this for more info.

For more information, you can refer to a couple tutorial guides on Spring AOP and play around with it to get a sense.

Nat
  • 3,587
  • 20
  • 22
  • I want to use it via spring xml configuration. Can you please provide a link for the examples as I am getting the example only for AfterReturning Advice instead on AfterAdvice. – Manish Dec 17 '15 at 04:29
  • I am not using aop namespaces. I am using basic xml configurations with ProxyFactoryBean. – Manish Dec 17 '15 at 04:32
  • Hi Nat, Thanks for your detailed explaination but my Query was that We can use the AfterAdvice using annotation So is there any way that we can also use AfterAdvice(Not AfterReturningAdvice) using xml Configuration. – Manish Dec 17 '15 at 14:11