Welcome 微信登录

首页 / 软件开发 / JAVA / Spring的AOP的annotation实现

Spring的AOP的annotation实现2011-02-17 csdn博客 海洋之心记录一下使用注解实现spring AOP的小例子。

第一步,导入相关的jar包:aspectjweaver-1.6.8.jar(提供注解org.aspectj.lang.annotation.Aspect等)、spring-aop-3.0.4.RELEASE.jar(提供自动代理创建器org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator)、aopalliance-1.0.jar(提供拦截器功能)。

第二步,配置applicationContext.xml

01.<?xml version="1.0" encoding="UTF-8"?>02.<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"03.xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"04.xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop"05.xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd06.http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd07.http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd08.http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd09.http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">10.<!--其他配置在此省略...-->11.<!--配置aop自动创建代理-->12.<aop:aspectj-autoproxy/>13.<bean id="userManager" class="com.service.Impl.UserManagerImpl"></bean>14.<bean class="com.util.SecurityHandler"></bean>15.</beans>
其中相关AOP的配置包括:

1、xmlns:aop="http://www.springframework.org/schema/aop"

2、xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd" 其中XSD的版本可以在spring-aop.jar中查看

3、<aop:aspectj-autoproxy/>

4、<bean class="com.util.SecurityHandler"></bean>在spring容器中添加切面类bean