Spring——AOP核心思想与实现
2017-07-26 16:03
351 查看
AOP(Aspect Oriented Programming):面向切面编程
核心思想:动态的添加和删除切面上的逻辑而不影响原来的执行代码
连接点,加入切面逻辑的位置。
2.PointCut
JoinPoint的一个集合
3.Aspect
指切面类,@Aspect
4.Advice
切面点上的业务逻辑
@Before;@AfterReturning;@Around ;…
5.Target
被代理对象
6.Weave
织入。将切面逻辑添加到原来执行代码上的过程。
2.xml
核心思想:动态的添加和删除切面上的逻辑而不影响原来的执行代码
AOP相关概念:
1.JoinPoint连接点,加入切面逻辑的位置。
@Before("execution(* com.spring.service..*.*(..))")
2.PointCut
JoinPoint的一个集合
@Pointcut("execution(* com.spring.service..*.*(..))") public void myMethod(){}; @Before("myMethod()") public void before(){ System.out.println("before"); }
3.Aspect
指切面类,@Aspect
4.Advice
切面点上的业务逻辑
@Before;@AfterReturning;@Around ;…
5.Target
被代理对象
6.Weave
织入。将切面逻辑添加到原来执行代码上的过程。
AOP概念图
Spring中AOP的实现
1.Annotation<!-- 找到被注解的切面类,进行切面配置 aop Annotation方法--> <aop:aspectj-autoproxy/>
@Aspect
@Component
public class LogInterceptor {
@Pointcut("execution(* com.spring.service..*.*(..))") public void myMethod(){}; @Before("myMethod()") public void before(){ System.out.println("before"); }
@Around("execution(* com.spring.dao.impl..*.*(..))")
public void
4000
aroundProcess(ProceedingJoinPoint pjp) throws Throwable{
System.out.println("around before");
pjp.proceed();
System.out.println("around after");
}
}
2.xml
<!-- aop xml方法 --> <bean id="logInterceptor" class="com.spring.aop.LogInterceptor"/> <aop:config> <aop:pointcut id="logPointcut" expression="execution(* com.spring.service..*.*(..))"/> <aop:aspect id="logAspect" ref="logInterceptor"> <aop:before method="before" pointcut-ref="logPointcut"/> </aop:aspect> </aop:config>
AOP原理解析
Spring AOP主要通过动态代理实现。Struts2中的interceptor就是AOP的一种实现。动态代理
相关文章推荐
- Spring AOP 实现和一些核心思想
- Spring 核心之 Ioc容器实现
- ext portal+dwr+spring实现个性主页面拖拉效果的核心代码
- Spring简介,整体架构和核心实现
- Spring的AOP思想研究和实现
- PHP实现链式操作的核心思想
- 穿NAT的方法的核心思想及实现
- (精)Spring IOC核心源码学习III:bean标签和自定义标签实现原理
- Spring全家桶(八)AOP核心思想与AspectJ 5种类型通知
- 【Spring 核心】(3):SpringMVC 的实现
- 通用权限实现的核心设计思想
- 透彻理解Spring事务设计思想之手写实现
- Spring核心——MessageSource实现国际化
- ssh整合思想 Spring与Hibernate的整合ssh整合相关JAR包下载 .MySQLDialect添加了第57区的方言解决没有异常,hibernate.dialect核心配置文件就是无法自动update创建表
- SpringMVC+freemarker实现菜单导航的思想一
- Spring三大核心思想一:IOC
- 【Spring 核心】(1):IOC容器的实现
- 【spring学习笔记三】aop思想介绍及实现原理
- 穿NAT的方法的核心思想及实现
- Spring 核心思想