services层:只是写了个简单的用来测试:
切面类:简单来说就是你用来处理事物的 这里要实现aop联盟接口;否则无法使用
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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 "> <!--配置切面类--> <bean id="MyAspect" class="com.fjs.Aop.MyAspect"></bean> <!--配置service层--> <bean id="userserice" class="com.fjs.Services.ServicesImpl"></bean> <!--spring 全自动aop配置--> <aop:config proxy-target-class="true"> <!--切入点--> <aop:pointcut id="MyPoincut" expression="execution(* com.fjs.Services.*.*(..))"/> <!--通知 关联 切入点--> <aop:advisor advice-ref="MyAspect" pointcut-ref="MyPoincut"/> </aop:config> </beans>
xml文件配置;
测试拦截成功 ;感觉很简单 代理被spring完成了;
最后我用的maven 写的要导入一个spring的aop.jar和一个aop联盟的接口包
spring的包网上多的是
下面是aop联盟的maven下载;
<!--AOP联盟接口--> <dependency> <groupId>aopalliance</groupId> <artifactId>aopalliance</artifactId> <version>1.0</version> </dependency>