Spring AOP:排除避免切入点的最终类和枚举

Spring AOP:排除避免切入点的最终类和枚举,第1张

概述我正在尝试使用Spring AOP实现Logging.我已定义了@Pointcut('execution(* com.mycom..*(..))') private void framework() {} @Around('framework()') public Object aroundAdviceFramework(ProceedingJoinPoi

我正在尝试使用Spring AOP实现Logging.我已定义了

@pointcut("execution(* com.mycom..*(..))")private voID framework() {}@Around("framework()")public Object aroundAdviceFramework(ProceedingJoinPoint jp) throws Throwable {    if (logger.isDeBUGEnabled())        logger.deBUG("DEBUG:: {}  {}  Enter",jp.getTarget().getClass().getname(),jp.getSignature().getname());    Object returnVal = jp.proceed(jp.getArgs());    if (logger.isDeBUGEnabled())        logger.deBUG("DEBUG:: {}  {}  Out",jp.getSignature().getname());    logger.info("INFO:: " + jp.getTarget().getClass().getname() + " " + jp.getSignature().getname() + " Finished:");    return returnVal;}

mycom包及其子包下有很多类.有些课程是enum和final class.
因此,我得到了

nested exception is org.springframework.aop.framework.AopConfigException: Could not generate cglib subclass of class [class com.mycom.util.BanCSServiceProvIDer]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Cannot subclass final class class com.mycom.util.BanCSServiceProvIDerat org.springframework.beans.factory.support.AbstractautowireCapablebeanfactory.doCreateBean(AbstractautowireCapablebeanfactory.java:529)

有没有办法使用某种正则表达式排除所有最终类和枚举类的日志记录.
注意:我在不同的包中都有枚举类.使用完整的类名排除它们很困难.

更新2014-11-17(尝试krIEgaex的解决方案):

我试过用

@pointcut("!within(is(FinalType))")

但我得到以下错误

pointcut is not well-formed: expecting ')' at character position 10

!内(是(FinalType))

我在pom文件中添加了这个maven依赖项

    

目前你不能做的是通过AspectJ语法排除最终类型.但我认为这是有道理的,所以我为它创造了一个ticket.

如何排除枚举:

@pointcut("execution(* com.mycom..*(..)) && !within(is(EnumType))")

更新:AspectJ 1.8.4已经发布,请参阅官方download section中的概述.在Maven Central上,下载尚不可用,但我想很快就会发布.如果可用,this link将有效,目前它产生404错误.

那么为什么这个版本很有趣?因为上面提到的票证已经解决,并且现在有一个新的切入点原语(FinalType),见1.8.4 release notes.

所以现在您要求的完整解决方案如下所示:

@pointcut(    "execution(* com.mycom..*(..)) && " +    "!within(is(EnumType)) && " +    "!within(is(FinalType))")

我确认它的工作原理是这样的. 总结

以上是内存溢出为你收集整理的Spring AOP:排除避免切入点的最终类和枚举全部内容,希望文章能够帮你解决Spring AOP:排除避免切入点的最终类和枚举所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/langs/1265231.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-08
下一篇 2022-06-08

发表评论

登录后才能评论

评论列表(0条)