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();
}
}
}