NutzCN Logo
问答 求助:aop 如何不拦截某些类
发布于 2220天前 作者 qq_7bff7329 1455 次浏览 复制 上一个帖子 下一个帖子
标签:

问题: 用了自定义的 CustomJsonAopConfigration 后,不走 signCheckInterceptor 签名栏截器了,直接跳过,
不知道是什么原因,麻烦看一下,谢谢!

aop.js 文件内容:

var ioc = {
    signCheckInterceptor : {
		type :'cn.guagua.mobile.interceptor.SignCheckInterceptor'
	},
		
	userValidityInterceptor : {
		type : "cn.guagua.mobile.interceptor.UserValidityInterceptor"
	},
	$aop : {
		type : 'cn.guagua.mobile.interceptor.CustomJsonAopConfigration',
		fields : {
			itemList : [
				['cn\\.guagua\\.mobile\\..+Module','.+','ioc:userValidityInterceptor'],
				['cn\\.guagua\\.mobile\\..+Module','.+','ioc:signCheckInterceptor'],
			]
		}
	},
	
	guaguaJsonView : {
		type : "cn.guagua.mobile.common.GuaguaJsonView"
	}
};
自定义jsonAop:

public class CustomJsonAopConfigration extends JsonAopConfigration{
	    
	@Override
    public List<InterceptorPair> getInterceptorPairList(Ioc ioc, Class<?> clazz) {
        List<InterceptorPair> ipList = new ArrayList<InterceptorPair>();
        List<AopConfigrationItem> aopItemList = new ArrayList<AopConfigrationItem>();
        for (AopConfigrationItem aopItem : aopItemList) {
            if (aopItem.matchClassName(clazz.getName()))
                ipList.add(new InterceptorPair(    getMethodInterceptor(    ioc,
                                                                        aopItem.getInterceptor(),
                                                                        aopItem.isSingleton()),
                                                MethodMatcherFactory.matcher(aopItem.getMethodName())));
        }
        return ipList;
    }

}
7 回复

判断一下,如果不需要拦截,返回null就可以了

@wendal 用了自定义的 CustomJsonAopConfigration 后,为什么走 signCheckInterceptor 签名栏截器了,直接跳过呢?

@wendal type : 'org.nutz.ioc.aop.config.impl.JsonAopConfigration', 这样设置就没有问题,会走signCheckInterceptor

那你自定义aopConfig是为了什么?

@wendal 说明一下: signCheckInterceptor.java 是接口签名拦截器,有些接口是需要签名验证的‘; 有些接口不想通过签名验证,就放到签名里了。但是后来发现签名拦截的方法太多了,我就想着在aop中拦截类。既然自定义的aop 不应该会影响其它的接口走签名拦截器

改成 $aop_custom 吧

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