Creating After Throwing Advice-1
After throwing advice executes when a matched method execution exits by throwing an exception. All the steps are same as the before and after advices. We have change the following code to run the advice.
Service.java
package com.visualbuilder.aop;
public interface Service {
public void testAdvice(String name) throws Exception;
}
|
ServiceImpl.java
package com.visualbuilder.aop;
public class ServiceImpl implements Service{
public void testAdvice(String name) throws Exception{
System.out.println("This is the Test Advice Method for Name " + name.length());
}
}
|
AdviceClass.java
package com.visualbuilder.aop;
public class AdviceClass {
public void beforeMethod(String name){
System.out.println("The method is advised.");
}
}
|
MainClass.java
package com.visualbuilder.aop;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public final class MainClass {
public static void main(String[] args){
BeanFactory ctx = new ClassPathXmlApplicationContext("com/visualbuilder/aop/beans.xml");
Service object = (Service) ctx.getBean("service");
try{
object.testAdvice(null);
//object.testAdvice("visualbuilder");
}catch(Exception e){
}
}
}
|