Spring AOP(创建切面)

Spring AOP的概念以及使用方法:

Spring AOP的可以使用方式有两种,网站空间,一种是使用注解,一种是使用配置文件。它的概念和术语篇幅比较长。

参考下面文章:Spring AOP

个人觉得spring AOP思想就是代理模式的思想

创建通知:

Spring 中的通知类型

通知类型

接口

描述

Arround

org.aopalliance.intercept.MethodInterceptor

拦截对目标对象方法调用

Before

org.springframework.aop.BeforeAdvice

在目标方法被调用之前调用

After

org.springframework.aop.AfterReturingAdvice

在目标方法被调用之后调用

Throws

org.springfrmaework.aop.ThrowsAdvice

当目标方法抛出异常时调用

例子:有个新生报到的功能,StudentService是功能接口,StudentServiceImp是StudentService接口的实现,分别为这个创建前置通知和后置通知.流程:在新生报到前,拦截新生,将新生带到辅导员处。注册后,虚拟主机,香港服务器,将新生带到宿舍安顿。

前置通知:

在方法调用前进行拦截器的调用,这里使用Spring提供的接口MethodBeforeAdvcie,它是BeforeAdvice的子类。需要注意的是,BefroeAdvice和MethodBeforeAdvice依赖的库在Spring中没有提供,要在以下地址下载:

, 下载文件为aopalliance-1.0.jar

com.sunflower.service.StudentService接口:

public interface StudentService {public void regist();}生活若剥去理想、梦想、幻想,那生命便只是一堆空架子

Spring AOP(创建切面)

相关文章:

你感兴趣的文章:

标签云: