理解spring AOP 详细工作方式
SPRING AOP 实际是将原对象引用为一个代理,此代理由proxyfactorybean或spring的自动代理类BeanNameAutoProxyCreator创建,代理实例包含被代理的对象,同时包含切入点和通知。当调用原对象是时,实际上调用的是代理,同时调用代理的通知方法,来达到AOP的目的。
下面是一个例子先看applicationContext.xml
?其次是环绕通知的实现MyInterceptor.java
package com.aop.managebeans;import javax.faces.bean.ManagedBean;import com.aop.service.MyService;public class LoginBean {private String name;private String passWord;private MyService myService;/** * @param myService the myService to set */public void setMyService(MyService myService) {this.myService = myService;}/** * @return the name */public String getName() {return name;}/** * @param name the name to set */public void setName(String name) {this.name = name;}/** * @return the passWord */public String getPassWord() {return passWord;}/** * @param passWord the passWord to set */public void setPassWord(String passWord) {this.passWord = passWord;}public String loginUser(){myService.sayHello(name);if(name.equals(passWord)){return "success";}return "error";}}?附件为源代码。为一个JSF2的WEB工程。