package com.fruitking.proxy.springaop; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import com.fruitking.proxy.CarService; public class TestSpringAOP { /** * 利用spring的AOP机制实现“代理”的横向抽取机制方式 * @param args */
public
static
void
main(String[] args) {
ApplicationContext ctx=
new
ClassPathXmlApplicationContext(
"beans.xml"
);
CarService carService = (CarService) ctx.getBean(
"carService"
);
carService.start();
carService.getLoadAmount();
String driver = carService.setDriver(
"fruitking"
);
System.out.println(driver);
System.out.println(
"------------------------------"
);
carService.loadGoods(
"Miss Mary"
);
System.out.println(
"------------------------------"
);
try
{
carService.loadGoods(
null
);
}
catch
(NullPointerException e){
e.printStackTrace();
}
System.out.println(
"------------------------------"
);
try
{
carService.loadGoods(
"tiger"
);
}
catch
(IllegalArgumentException e){
e.printStackTrace();
}
}
}
代理模式,JDK动态代理,SpringAOP来龙去脉(2)
最新推荐文章于 2023-02-27 09:00:00 发布