网站建设与维护教案,厚街外贸网站建设公司,wordpress怎么添加文章,网络营销推广方案步骤一、AOP是OOP的延续#xff0c;是#xff08;Aspect Oriented Programming#xff09;的缩写#xff0c;意思是面向切面编程。 AOP#xff08;Aspect Orient Programming#xff09;#xff0c;作为面向对象编程的一种补充#xff0c;广泛应用于处理一些具有横切性质的…一、AOP是OOP的延续是Aspect Oriented Programming的缩写意思是面向切面编程。 AOPAspect Orient Programming作为面向对象编程的一种补充广泛应用于处理一些具有横切性质的系统级服务 如事务管理、安全检查、缓存、对象池管理等。 AOP 实现的关键就在于 AOP 框架自动创建的 AOP 代理 AOP 代理则可分为静态代理和动态代理两大类其中静态代理是指使用 AOP 框架提供的命令进行编译 从而在编译阶段就可生成 AOP 代理类因此也称为编译时增强 而动态代理则在运行时借助于 JDK 动态代理、CGLIB 等在内存中临时生成 AOP 动态代理类因此也被称为运行时增强 AOP 的实现 MyInterceptor、MyInterceptor2分别是以annotations和xml定义的切面类 package com.service; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Pointcut; Aspect public class MyInterceptor { Pointcut(execution (* com.serviceImpl.PersonServiceImpl.*(..))) private void myMethod(){}; Before(myMethod()) public void doAccessCheck(){ System.out.println(before); } } [java] view plain copy package com.service; public class MyInterceptor2 { public void doAccessCheck(){ System.out.println(before); } } 业务和接口 [java] view plain copy package com.service; public interface PersonService { public void save(String name); public void update(String name); } [java] view plain copy package com.serviceImpl; import com.service.PersonService; public class PersonServiceImpl implements PersonService { Override public void save(String name) { // TODO Auto-generated method stub System.out.println(保存); } Override public void update(String name) { // TODO Auto-generated method stub System.out.println(修改); } } 简单做个方法前通知,其他的都一样。 [java] view plain copy ?xml version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beans xmlns:xsihttp://www.w3.org/2001/XMLSchema-instance xmlns:aophttp://www.springframework.org/schema/aop xsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd aop:aspectj-autoproxy/ bean idpersonServiceImpl classcom.serviceImpl.PersonServiceImpl/bean bean idpersonInterceptor classcom.service.MyInterceptor2/bean aop:config aop:aspect idasp refpersonInterceptor aop:pointcut idmyCut expressionexecution (* com.serviceImpl.PersonServiceImpl.*(..))/ aop:before pointcut-refmyCut methoddoAccessCheck/ /aop:aspect /aop:config /beans 测试类 [java] view plain copy package com.test; import org.junit.Test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import com.service.PersonService; public class AopTest { Test public void interceptorTest(){ ApplicationContext ac new ClassPathXmlApplicationContext(beans.xml); PersonService ps (PersonService) ac.getBean(personServiceImpl); ps.save(aa); } } 转载于:https://www.cnblogs.com/lihaiyang123/p/7084595.html