Spring AOP 代理配置笔记

3 篇文章 0 订阅



<?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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值