aspectj xml
2021-06-11 02:05
标签:ref span ora +++ aspect instance image 1.2 对象 1.接口和类 1.1 ISomeService 接口 1.2 SomeService类 1.3 MyAspect 类 2.xml文件 3.测试类 aspectj xml 标签:ref span ora +++ aspect instance image 1.2 对象 原文地址:http://www.cnblogs.com/qjt970518--/p/7293925.htmlpublic interface ISomeService {
public void doSome();
public void dade();
}
public class SomeService implements ISomeService {
//核心业务
public void doSome(){
System.out.println("我们都要找到Java开发工作,薪资6,7,8,9,10K");
}
public void dade() {
//异常
//int sun=5/0;
System.out.println("++++++++++++++de+++++++++++++");
}
}
public class MyAspect {
//前置增强
public void before(){
System.out.println("=====before========");
}
//后置增强
public void afterReturing(){
System.out.println("=====after========");
}
//后置增强 目标方法的返回值
public void afterReturing(String result){
System.out.println("=====后置通知方法 result========"+result);
}
//环绕通知
public Object around(ProceedingJoinPoint pjp) throws Throwable {
System.out.println("目标方法执行前执行");
Object result = pjp.proceed();
System.out.println("目标方法执行后执行");
String temp=null;
if (result!=null) {
temp = (String) result;
temp=temp.toUpperCase();
}
return temp;
}
//异常通知
public void afterThrowing(){
System.out.println("异常通知");
}
//异常通知
public void afterThrowing(Exception ex){
System.out.println("异常通知 ex="+ex.getMessage());
}
//最终通知
public void after(){
System.out.println("最终通知");
}
}
"1.0" encoding="UTF-8"?>
//aspectj xml
@Test
public void test20(){
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContextspring16.xml");
ISomeService service = (ISomeService) ctx.getBean("someService");
service.doSome();
service.dade();
}