spring aop xml配置

CommonIntercptor.java

/**
 * 
 */
package  org.spring.aop.intercept;

/**
 * @author zhangcp
 * 
 */
public class CommonIntercptor{

	public void dobeforeMethod() {
		
	}

	public void doafterMethod() {
	}

	public void doafterReturningMethod() {
	}

	public void doafterThrowingrMethod() {
	}

	public void doaroundMethod() {
	}
}

 applicatonContext.xml

 

<?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-2.5.xsd
          http://www.springframework.org/schema/context
          http://www.springframework.org/schema/context/spring-context-2.5.xsd
          http://www.springframework.org/schema/aop
          http://www.springframework.org/schema/aop/spring-aop-2.5.xsd ">
   
 	<!-- 启用aop自动代理 -->
	<aop:aspectj-autoproxy/>
	<!-- 注入切面拦截器 -->
	<bean id="commonIntercptor" class="org.spring.aop.intercept.CommonIntercptor"/>
	<aop:config>
			<!-- 定义切面 -->
			<aop:aspect id="aspect" ref="commonIntercptor">
					<!-- 定义切入点 -->
					<aop:pointcut expression="'execution(* com.xyz.myapp.service.*.*(..))" id="pointcut"/>
	<!-- 
	切入点表达式的解释
	1 * com.xyz.myapp.service.*.*(..)  表示拦截com.xyz.myapp.service包下所有类的所有方法,并且不管参数是多少和参数是什么类型,所有返回类型的方法
	2 !void com.xyz.myapp.service.*.*(..)  表示拦截com.xyz.myapp.service包下所有类的所有方法,并且不管参数是多少和参数是什么类型,只有返回类型不是void类型的方法
	3 !void com.xyz.myapp.service..*.*(..)  表示拦截com.xyz.myapp.service包下所有类和所有子包下的所有类的所有方法,并且不管参数是多少和参数是什么类型,只有返回类型不是void类型的方法
	4 * com.xyz.myapp.service.*.*(java.lang.String,..)  表示拦截com.xyz.myapp.service包下所有类的所有方法,并且第一个参数是String类型,不管后面参数是多少和后面参数的类型,所有返回类型的方法
	5 * com.xyz.myapp.service.UserService.*(..)  表示拦截com.xyz.myapp.service.UserService类的所有方法,并且不管参数是多少和参数是什么类型,所有返回类型的方法
	-->
					<aop:before method="dobeforeMethod" pointcut="pointcut"/><!-- 前置通知 -->
					<aop:after method="doafterMethod" pointcut="pointcut"/><!-- 最终通知 -->
					<aop:after-returning method="doafterReturningMethod" pointcut="pointcut"/><!-- 后置通知 -->
					<aop:after-throwing method="doafterThrowingrMethod" pointcut="pointcut"/><!-- 例外通知 -->
					<aop:around method="doaroundMethod" pointcut="pointcut"/><!-- 环绕通知 -->
			</aop:aspect>
	</aop:config>
	

	
</beans> 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值