Spring   发布时间:2022-04-09  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Spring AOP:排除避免切入点的最终类和枚举大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

我正在尝试使用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;
}
@H_704_1@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.bancsserviceProvider
at 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依赖项

    <><><>

我还添加了这个maven依赖项

   <><><>

现在,一切都像魅力一样.有什么想法,这里发生了什么?

最佳答案
目前,您可以通过在AspectJ 1.6.9中引入的is()切入点语法来排除枚举,方面,接口,内部类型,匿名类型,另请参阅我的答案here.

目前你不能做的是通过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:排除避免切入点的最终类和枚举所遇到的程序开发问题。

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

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。