Spring事务处理及其AOP框架的内幕 (3)
以上就是配置文件,现在我们假设使用业务对象如下,这里是一个简单测试类:
//$ID:MainApp.java Created:2005-11-6 by Kerluse Benn
package com.osiris.springaop;
import java.util.Date;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.FileSystemResource;
import com.osiris.springaop.advices.intruduction.IAuditable;
public class MainApp {
/**
* @param args
* @author Kerluse Benn
*/
public static void main(String[] args) throws Exception{
// TODO Add your codes here
BeanFactory factory=new XmlBeanFactory(new FileSystemResource("bean.xml"));
BookService bookService=(BookService)factory.getBean("BookService");
IAuditable auditable=(IAuditable)bookService;
System.out.print(bookService.OrderBook("Kerluse Benn","Professional C#"));
auditable.setLastModifiedDate(new Date());
System.out.println(" 订购时间为"+auditable.getLastModifiedDate());
Thread.sleep(10000);
System.out.print(bookService.OrderBook("Kerluse Benn","Expert j2ee one-on-one"));
auditable.setLastModifiedDate(new Date());
System.out.println(" 订购时间为"+auditable.getLastModifiedDate());
字串3
}
}
输出结果:
订购Professional C#成功 订购时间为Mon Nov 07 11:35:20 CST 2005
订购Expert j2ee one-on-one成功 订购时间为Mon Nov 07 11:35:30 CST 2005
看见上面黑体字:
IAuditable auditable=(IAuditable)bookService;
由于bookService对象事实上已经实现了IAuditable接口,通过Spring AOP的introduction切入实现,所以在运行时(熟悉C++的vtable模型的可以在大脑里想一下)可以转换,我们就可以随意添加自己的接口方法了.
//$ID:MainApp.java Created:2005-11-6 by Kerluse Benn
package com.osiris.springaop;
import java.util.Date;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.FileSystemResource;
import com.osiris.springaop.advices.intruduction.IAuditable;
public class MainApp {
/**
* @param args
* @author Kerluse Benn
*/
public static void main(String[] args) throws Exception{
字串5
// TODO Add your codes here
BeanFactory factory=new XmlBeanFactory(new FileSystemResource("bean.xml"));
BookService bookService=(BookService)factory.getBean("BookService");
IAuditable auditable=(IAuditable)bookService;
System.out.print(bookService.OrderBook("Kerluse Benn","Professional C#"));
auditable.setLastModifiedDate(new Date());
System.out.println(" 订购时间为"+auditable.getLastModifiedDate());
Thread.sleep(10000);
System.out.print(bookService.OrderBook("Kerluse Benn","Expert j2ee one-on-one"));
auditable.setLastModifiedDate(new Date());
System.out.println(" 订购时间为"+auditable.getLastModifiedDate());
字串3
}
}
输出结果:
订购Professional C#成功 订购时间为Mon Nov 07 11:35:20 CST 2005
订购Expert j2ee one-on-one成功 订购时间为Mon Nov 07 11:35:30 CST 2005
看见上面黑体字:
IAuditable auditable=(IAuditable)bookService;
由于bookService对象事实上已经实现了IAuditable接口,通过Spring AOP的introduction切入实现,所以在运行时(熟悉C++的vtable模型的可以在大脑里想一下)可以转换,我们就可以随意添加自己的接口方法了.
Tags:
责任编辑:您的评论
·用户发表意见仅代表其个人意见,并且承担一切因发表内容引起的纠纷和责任
·本站管理人员有权在不通知用户的情况下删除不符合规定的评论信息或留做证据
·请客观的评价您所看到的资讯,提倡就事论事,杜绝漫骂和人身攻击等不文明行为
·本站管理人员有权在不通知用户的情况下删除不符合规定的评论信息或留做证据
·请客观的评价您所看到的资讯,提倡就事论事,杜绝漫骂和人身攻击等不文明行为
精彩推荐
最新资讯


您的位置: