Spring学习笔记(二)----Spring AOP配置与应用
来源:互联网 发布:淘宝网上兼职靠谱吗 编辑:程序博客网 时间:2024/04/20 11:23
一、什么是AOP
1. 面向切面编程Aspect-Oriented-Programming
a) 是对面向对象的思维方式的有力补充
2. 参考Spring_1400_AOP_Introduction
3. 好处:可以动态的添加和删除在切面上的逻辑而不影响原来的执行代码
a) Filter
b) Struts2的interceptor
4. 概念:
a) JoinPoint
b) PointCut
c) Aspect(切面)
d) Advice
e) Target
f) Weave
二、Spring AOP配置与应用
1. 两种方式:
a) 使用Annotation
b) 使用xml
2. Annotation
a) 加上对应的xsd文件spring-aop.xsd
b) beans.xml <aop:aspectj-autoproxy/>
c) 此时就可以解析对应的Annotation了
d) 建立我们的拦截类
e) 用@Aspect注解这个类
f) 建立处理方法
g) 用@Before来注解方法
h) 写明白切入点(execution …….)
i) 让spring对我们的拦截器类进行管理@Component
3. 常见的Annotation:
a) @Pointcut
b) @Before
c) @AfterReturning
d) @AfterThrowing
e) @After
f) @Around
@Aspect@ComponentpublicclassLogInterceptor { @Pointcut("execution(public* com.bjsxt.service..*.add(..))") publicvoidmyMethod(){}; @Before("myMethod()") publicvoidbefore() { System.out.println("methodbefore"); } @AfterReturning("myMethod()") publicvoid afterReturning(){ System.out.println("methodafter returning"); } @Around("myMethod()") publicvoidaroundMethod(ProceedingJoinPoint pjp)throwsThrowable { System.out.println("methodaround start"); pjp.proceed(); System.out.println("methodaround end"); }}
4. 织入点语法
a) void !void
b) 参考文档(* ..)
5. xml配置AOP
a) 把interceptor对象初始化
b) <aop:config
<aop:aspect …..
<aop:pointcut
<aop:before
- Spring学习笔记(二)----Spring AOP配置与应用
- spring学习笔记(8)AOP增强(advice)配置与应用
- Spring学习笔记(二)后处理器与AOP
- Spring AOP配置与应用
- Spring AOP配置与应用
- Spring 学习笔记 (二)--AOP
- Spring学习笔记(二)AOP入门
- Spring学习笔记(一)----Spring IOC配置与应用
- spring学习笔记(3)--spring环境配置与应用
- Spring-AOP配置(学习笔记)
- AOP学习笔记(二)——Spring AOP
- Spring(二)Spring AOP配置详解
- Spring(二)Spring AOP配置详解
- 【SSH】Spring学习(二)使用注解配置Spring、安装STS插件、Spring与junit整合测试、AOP
- [Spring]Spring AOP学习笔记(1)
- Spring学习笔记(二)IOC和AOP
- Spring源码学习笔记(二)-AOP基础简介
- Spring新手学习笔记(二)后处理器与AOP 1048693.shtml
- nginx 301重定向
- Ubuntu/Kubuntu Objective-C 开发环境搭建
- ios播放PCM数据
- javadoc做注释
- Spring学习笔记(一)----Spring IOC配置与应用
- Spring学习笔记(二)----Spring AOP配置与应用
- Spring学习笔记(三)----Spring整合Hibernate
- 正则表达式组成规则
- I love sneakers! 分组背包(每组至少选一件)
- 阅读代码的方法
- Python tuple 元组详解
- 性能测试工具之研究http://www.51testing.com/html/52/143.html
- C 程序,写运行结果,考察多态
- HDU 1222 欧几里德公式扩展