您的位置:首页 > 编程语言 > ASP

Spring AOP编程-传统基于aspectJ切点AOP开发

2018-02-10 16:36 405 查看
1、在配置文件上方增加aop相关配置。

2、在spring的配置文件中定义目标与通知.

3、使用aop:xxx标签来完成切面与切点声明。

4、我们使用aspectj的切面声明方式 需要在导入aspectj的jar包.



<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">

<!-- 目标target -->
<bean id="orderService" class="cn.nwtxxb.aop.OrderServiceImpl"></bean>
<!-- 通知advice -->
<bean id="orderServiceAdvice" class="cn.nwtxxb.aop.OrderHelper"></bean>

<!-- 使用aop标签来完成切面与切点声明 -->
<aop:config>
<!-- 定义切点 -->
<aop:pointcut expression="execution(* cn.nwtxxb.aop.IOrderService.*(..))"
id="orderServicePointCut" />
<!-- 定义切面 -->
<aop:advisor advice-ref="orderServiceAdvice" pointcut-ref="orderServicePointCut" />
<!-- <aop:aspect></aop:aspect> aspectj框架它定义切面使用的 -->
</aop:config>
</beans>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  aspectj aop spring