Spring AOP 代理配置笔记

来源:互联网 发布:mac dota2 鼠标巨大 编辑:程序博客网 时间:2024/05/19 22:24



<?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/aop http://www.springframework.org/schema/aop/spring-aop.xsd          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"><!-- 打开Spring的Annotation的支持 --><!-- AutowiredAnnotationBeanPostProcessor、CommonAnnotationBeanPostProcessor、 PersistenceAnnotationBeanPostProcessor 以及 RequiredAnnotationBeanPostProcessor 这 4 个BeanPostProcessor。 注册这4个 BeanPostProcessor的作用,就是为了系统能够识别相应的注解。 --><!-- <context:annotation-config /> --><!-- 告诉Spring去哪些包中找Annotation --><!-- <context:component-scan base-package="boa.framework" /> --><context:component-scan base-package="boa.framework.controller" /><context:component-scan base-package="boa.framework.service" /><context:component-scan base-package="boa.framework.aspect" /><context:component-scan base-package="boa.framework.dao" /><aop:aspectj-autoproxy /><!-- 配置示例 --><aop:config><!-- 定义切面 --><aop:aspect id="mygreetingAspect" ref="greetingAspect"><!-- 加入相应的Aspect --><aop:pointcut id="greetingPointCut"expression="execution(* boa.framework.dao.*.add*(..))||execution(* boa.framework.dao.*.update*(..))||execution(* boa.framework.dao.*.delete*(..))" /><!-- 方法之前执行 --><aop:before method="sayHello" pointcut-ref="greetingPointCut" /><!-- 方法之后执行 --><aop:after method="after" pointcut-ref="greetingPointCut" /><aop:around method="around" pointcut-ref="greetingPointCut" /></aop:aspect></aop:config><bean id="exceptionLog" class="boa.framework.aspect.ExceptionLog"></bean>    <!-- beanName自动代理 --><bean id="logAdvice"class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"><property name="beanNames"><list><value>userDAO</value></list></property><property name="interceptorNames"><list><value>exceptionLog</value></list></property></bean></beans>

0 0
原创粉丝点击