Spring: 全自动AOP实现

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>

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值