spring 小问题,那个高手帮忙看哈~~~~~~~

AOP中自己写了一个切点,还有一个方法前通知,其中代码是这样的:
前置通知:
package advice;

import java.lang.reflect.Method;

import org.springframework.aop.MethodBeforeAdvice;

public class beforeadvice implements MethodBeforeAdvice {

public void before(Method arg0, Object[] arg1, Object arg2)
throws Throwable {
// TODO Auto-generated method stub

System.out.println(arg2.getClass().getName()+"----"+arg0.getName()+"----"+"前置增强完成");
}

}
切点:
package advice;

import java.lang.reflect.Method;

import org.springframework.aop.ClassFilter;
import org.springframework.aop.support.StaticMethodMatcherPointcutAdvisor;

public class greetingadvisor extends StaticMethodMatcherPointcutAdvisor {

public boolean matches(Method arg0, Class arg1) {
// TODO Auto-generated method stub

return "greetto".equals(arg0.getName());
}

}
目标类:
package advice;

public class naivewaiter implements waiter {

public void greetto(String name) {
// TODO Auto-generated method stub
System.out.println("greet to "+name);

}

public void serveto(String name) {
//TODO Auto-generated method stub
System.out.println("serving "+name);
}

}

配置文件:
<bean id="beforeAdvice" class="advice.beforeadvice"></bean>
<bean id="greetingadvisor" class="advice.greetingadvisor" >
<property name="advice" ><ref bean="beforeAdvice"/></property>
</bean>
<bean id="nwaiter" class="advice.naivewaiter"></bean>

<bean id="waiter" class="org.springframework.aop.framework.ProxyFactoryBean" >
<property name="proxyInterfaces">
<value>advice.waiter</value>
</property>
<property name="interceptorNames">
<list>
<value>beforeAdvice</value>
</list>
</property>
<property name="target" ref="nwaiter"/>
</bean>
目标类接口:
package advice;

public interface waiter {
void greetto(String name);
void serveto(String name);
}
主函数:
public static void main(String[] args) {
// TODO Auto-generated method stub
ApplicationContext ctx=new ClassPathXmlApplicationContext("applicationContext.xml");
//sell sell1=(sell)ctx.getBean("s");
waiter w=(waiter)ctx.getBean("waiter");

w.greetto("yinfan");
w.serveto("xiaoqiang")
问题1:
为什么我这样一个方法前通知结果打印了三跳语句啊?
结果是:
$Proxy0----greetto----前置增强完成
$Proxy0----greetto----前置增强完成
advice.naivewaiter----greetto----前置增强完成
greet to yinfan
serving xiaoqiang
问题2:
waiter w=(waiter)ctx.getBean("waiter");
这里的waiter 是接口,我换成实现接口的类就不行了?这个是为什么呢?是不是这里必须要用接口啊?
问题3:
配置文件中全部都用的JDK代理,要是我换成CGLIB代理就说finanl不能继承~~~~~~~这个是为什么呢?
希望高手帮我看哈嘛 谢谢~~~~~~~~
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值