本页主题: DefaultAdvisorAutoProxyCreator代理
lei004
积分:60
发表主题:56
发表于 2009-06-23 17:29 资料
楼主
DefaultAdvisorAutoProxyCreator代理应该是动态代理,既然是动态代理:代理类就需要接口,那么为什么下面的例子没有接口的类也能够被代理: package chapter4.onlyfun.caterpillar.RegexpMatchDemo; public class HelloSpeaker2 { public void helloMaster(String name) { System.out.println("Hello,"+name+" newbie!"); } public void hello1Newbie(String name) { System.out.println("Hello,"+name+" master!"); } } package chapter4.onlyfun.caterpillar.RegexpMatchDemo; import java.lang.reflect.Method; import java.util.logging.Level; import java.util.logging.Logger; import org.springframework.aop.MethodBeforeAdvice; public class LogBeforeAdvice implements MethodBeforeAdvice { private Logger logger = Logger.getLogger(this.getClass().getName()); public void before(Method method, Object[] args, Object target) throws Throwable { logger.log(Level.INFO, "liuyi method starts..." + method); } } package chapter4.onlyfun.caterpillar.RegexpMatchDemo; import org.springframework.context.support.FileSystemXmlApplicationContext; import chapter3.onlyfun.caterpillar.AutoWireDemo.SpringDemo; public class SpringAOPDemo { public static void main(String[] args) { FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext( new SpringAOPDemo().getAbsolutePath() + "/beans-config_DetAdvisorAutoProxyCreator.xml"); HelloSpeaker2 helloProxy=(HelloSpeaker2)context.getBean("helloSpeaker2"); helloProxy.hello1Newbie("Justin"); helloProxy.helloMaster("caterpillar"); } private String getAbsolutePath() { return this.getClass().getResource("").getPath().toString(); } } <?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-2.0.xsd"> <bean id="logBeforeAdvice" class="chapter4.onlyfun.caterpillar.RegexpMatchDemo.LogBeforeAdvice"> </bean> <bean id="regExpAdvice" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor"> <property name="pattern"> <value>.*Newbie </value> </property> <property name="advice" ref="logBeforeAdvice"> </property> </bean> <bean id="helloSpeaker2" class="chapter4.onlyfun.caterpillar.RegexpMatchDemo.HelloSpeaker2"> </bean> <bean id="autoProxyCreator" class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"> </bean> </beans> 回复1: 没人给大家了。。。顶下