1. 程式人生 > >AOP 有介面使用cglib

AOP 有介面使用cglib

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans.xsd">

		<!-- 註冊目標物件 -->
		<bean id="someService" class="com.gqc.aop08.SomeServiceImpl"/>
	
		<!-- 註冊切面:後置通知 -->
		<bean id="myAdvice" class="com.gqc.aop08.MyAfterReturningAdvice"/>
		
		<!-- 生成代理物件 -->
		<bean id="serviceProxy" class="org.springframework.aop.framework.ProxyFactoryBean">
			<!-- 指定目標物件 -->
			<property name="target" ref="someService"/>
			<!-- <property name="targetName" value="someService"/> -->
			<!-- 指定切面 -->
			<property name="interceptorNames" value="myAdvice"/>
			<property name="optimize" value="true"/> <!-- 這兩種方法話都可以 有介面使用cglib-->
			<!-- <property name="proxyTargetClass" value="true"/> 加上這句可以有介面使用cglib -->
		</bean>
				
</beans>