spring aop 面向切面编程,核心动态代理
一、切面和切点的概念:
以一个用户service为例子,如果说所有的方法都要增强,我们可以说是面向切面,如果说针对某些方法,那么可以说是切点。
自动生成代理【面向切面】:
自动生成代理,采用通配符的形式,要求在代理目标命名时要统一化。
test test2注意:调用时只需要使用spring中配置目标本身的bean name
生成切点代理【面向切点】:
二、spring中的AspectJ的切面开发
自定义一个通知类,里面写上相应的通知方法:
Around 环绕
Before 前置
After 后置
Throws 异常等等
ps:如果是环绕通知,要传递参数ProceedingJoinPoint对象
spring中配置:
aop:config
<aop:aspect ref=“myAdvice”>
<aop:pointcut expression=“execution(* dao..(…))” id=“point_cut”/>
<!-- 在指定的切点上做指定的事情 -->
<!-- 指定的切点用pointcut-ref属性来引用 -->
<!-- 做的具体事情用method属性来指定 -->
<!-- aop:before前置通知 -->
<aop:before method="doBefore" pointcut-ref="point_cut"/>
<!-- aop:after后置通知 -->
<aop:after method="doAfter" pointcut-ref="point_cut"/>
<!-- aop:after异常通知 -->
<aop:after-throwing method="doException" pointcut-ref="point_cut"/>
</aop:aspect>
</aop:config>
三、spring和hibernate集成
稳定版本,hibernate3.2 + spring3.0
导入jar包集:
spring 3.0 core、j2ee、aop、persisence Core、persisence jdbc、web
hibernate 3.2 core、Annotations
来源:CSDN
作者:qq_45990281
链接:https://blog.csdn.net/qq_45990281/article/details/104613344