NutzCN Logo
精华 Module子类继承父类想重写父类的方法,但是AOP依然生效
发布于 3254天前 作者 jpoppy 2425 次浏览 复制 上一个帖子 下一个帖子
标签:

untitled1_png

如图所示在子类继承父类想重写父类的方法,但是AOP依然生效,打断点的话程序执行的是子类的方法

7 回复

声明个空的

@wendal 定义了个空的AOP,还是不行

@IocBean
public class NoAop implements MethodInterceptor {

	@Override
	public void filter(InterceptorChain chain) throws Throwable {
		chain.doChain();
	}

}

在子类方法上重新定义,结果还是一样的,跟断点的话先进入的子类方法的AOP,然后又执行到父类的AOP了

@At("/ping")
	@Aop("noAop")
	public Object ping() {
		// new Throwable().printStackTrace();
		return new Date();
	}

@wendal

java.lang.Throwable
	at com.poppy.modules.ExtendMoudle.ping(ExtendMoudle.java:14)
	at com.poppy.modules.ExtendMoudle$$NUTZAOP._aop_invoke(ExtendMoudle.java:1)
	at org.nutz.aop.InterceptorChain.invoke(InterceptorChain.java:77)
	at org.nutz.aop.InterceptorChain.doChain(InterceptorChain.java:57)
	at com.poppy.aop.SuppAop.filter(SuppAop.java:12)
	at org.nutz.aop.InterceptorChain.doChain(InterceptorChain.java:60)
	at com.poppy.aop.NoAop.filter(NoAop.java:12)
	at org.nutz.aop.InterceptorChain.doChain(InterceptorChain.java:60)
	at com.poppy.modules.ExtendMoudle$$NUTZAOP.ping(ExtendMoudle.java)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:25)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:33)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:40)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:113)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
	at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:40)
	at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
	at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
	at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:183)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:745)

嗯,两个拦截器都生效了,看来是其他原因,翻一下源码吧

@wendal 算是个BUG么 ,多谢 我仔细跟下吧

没想过会这样,理应当前方法的配置才生效

不过可以给你个临时解决方式,就是写个代理方法,在代理方法上aop,然后原方法去调用,这样原方法上就不需要aop注解。

添加回复
请先登陆
回到顶部