Spring3

不羁的心 提交于 2020-03-05 07:03:54

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!