1.AOP terminology
1. Joinpoint(连接点):所谓连接点是指那些被拦截到的点。在spring中,这些点指的是方法,因为spring只支持方法类型的连接点2. Pointcut(切入点):所谓切入点是指我们要对哪些Joinpoint进行拦截的定义3. Advice(通知/增强):所谓通知是指拦截到Joinpoint之后所要做的事情就是通知.通知分为前置通知,后置通知,异常通知,最终通知,环绕通知(切面要完成的功能)4. Introduction(引介):引介是一种特殊的通知在不修改类代码的前提下, Introduction可以在运行期为类动态地添加一些方法或Field5. Target(目标对象):代理的目标对象6. Weaving(织入):是指把增强应用到目标对象来创建新的代理对象的过程7. Proxy(代理):一个类被AOP织入增强后,就产生一个结果代理类8. Aspect(切面):是切入点和通知的结合,以后咱们自己来编写和配置的
2.AOP simple implementation of ASPECTJ-based XML method
1. Introduction of the JAR package
Sprig Framework foundation Package +JUNTIL Integration Pack + Log Pack +AOP package
spring的传统AOP的开发的包
spring-aop-4.2.4.RELEASE.jar
com.springsource.org.aopalliance-1.0.0.jar
aspectJ的开发包
com.springsource.org.aspectj.weaver-1.6.8.RELEASE.jar
spring-aspects-4.2.4.RELEASE.jar
2. Introduction of configuration files (AOP constraints)
< beans xmlns = "Http://www.springframework.org/schema/beans" Xmlns:xsi = "Http://www.w3.org/2001/XMLSchema-instance" XMLNS:AOP = "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP" xsi:schemalocation = "Http://www.springframework.org/schema/beans Http://www.springframework.org/sche Ma/beans/spring-beans.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP http://www.springframework.org/schema/aop/s Pring-aop.xsd " > </ bean >
3. Create an implementation class
Public Interface UserService { publicvoid Save (); Public void update ();}
Public class Implements userservice { @Override publicvoid Save () { // TODO auto-generated Method Stub System.out.println ("Save User:" ); } @Override publicvoid update () { // TODO auto-generated method Stub System.out.println ("Update User:" ); }}
4. Hosting the implementation class in spring
<!--- < id = "UserService" class = "Com.spring.demo1.UserServiceImpl"/>
5. Defining Slice Classes
Public class Logimpl { publicvoid log () { System.out.println ("Logging ....") ); }}
6. Hosting a slice class in spring
<!--- < id = "Logimpl" class = "Com.spring.demo1.LogImpl"/>
7. Complete the AOP configuration in the configuration file
<!--Configuring AOP - <Aop:config> <!--Configure slice classes: pointcuts and Notifications - <Aop:aspectref= "Logimpl"> <Aop:beforeMethod= "Log"pointcut= "Execution (public void Com.spring.demo1.UserServiceImpl.save ())"/> </Aop:aspect> </Aop:config>
8. Writing test Code
@RunWith (Springjunit4classrunner. Class) @ContextConfiguration ("Classpath:applicationContext.xml")Publicclass Test1 { @Resource (name= "UserService") private UserService UserService; @Test publicvoid m01 () { userservice.save (); Userservice.update (); } }
Effect:
Simple implementation of AOP terminology and XML in 6.Spring