博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
spring学习--4
阅读量:5878 次
发布时间:2019-06-19

本文共 1731 字,大约阅读时间需要 5 分钟。

参考书籍《spring in action》
 
1. AOP
before you wak the walk, you have to learn to walk the walk.
1) advice---the job of an aspect (what and when)
/before
/after
/after-returning
/after throwing
/around: beforen and after
2) join points---a point in the execution of the application where an aspect can be plugged in.
3)pointcuts---where the advice should be woven
4)aspects--- advice & joincuts
5)introduction---add new methods or attributes to existing classes.
6)weaving---the process of applyng aspects to target object to create a
 new proxied object.
/compile time
/class load time
/runtime
2. spring 对AOP的支持方式
1)classic spring proxy-based AOP
2)pure-POJO aspects
3) @AspectJ annotation driven aspects.
4) injected AspectJ aspects.
 
3.creating aspect in spring
1)selecting join points with pointcuts.
eg:
execution(* concert.Performance.perform())
and bean('woodstock')
2) creating annotated aspects
@Aspectpublic class Audience {@Pointcut("execution(** concert.Performance.perform(..))")public void performance() {}@Before("performance()")public void silenceCellPhones() {System.out.println("Silencing cell phones");}@Before("performance()")public void takeSeats() {System.out.println("Taking seats");}@AfterReturning("performance()")public void applause() {System.out.println("CLAP CLAP CLAP!!!");}@AfterThrowing("performance()")public void demandRefund() {System.out.println("Demanding a refund");}}

配置:

@Configuration@EnableAspectJAutoProxy@ComponentScanpublic class ConcertConfig {@Beanpublic Audience audience() {return new Audience();}}

3)handling params in advice

 

4) annotation introductions

dynamic language like ruby and groovy can add new methods to an object or class.

 
 

转载于:https://www.cnblogs.com/flyingbee6/p/5351676.html

你可能感兴趣的文章
EntityFramework之一对一关系(二)
查看>>
获取表的信息,包含字段的描述
查看>>
Mybatis学习
查看>>
C# 的关键字系列 (2 of n)
查看>>
runtime第三部分方法和消息
查看>>
C# Enum,Int,String的互相转换 枚举转换
查看>>
python 数值系列-进制转换
查看>>
预测和交易大型股票指数的高频波动率
查看>>
在既定状态下截图
查看>>
JAVA android 点击两次返回键退出
查看>>
JAVA入门到精通-第42讲-坦克大战9
查看>>
【转载】Python 代码调试技巧
查看>>
Winform和WPF也使用Sql Server CE4.0和EF的简单方法
查看>>
通过idea 打包 spring maven项目打包为可执行jar包
查看>>
python-xlrd api
查看>>
js高级程序设计学习之高级函数
查看>>
Nginx + Tomcat + Session
查看>>
oracle分配权限 学习笔记--转载
查看>>
Flex builder 3 调试
查看>>
带头尾和动画的下拉刷新RecyclerView
查看>>