【发布时间】:2014-10-31 14:04:33
【问题描述】:
我正在尝试使用 Spring AOP 实现日志记录。我已经定义了
@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.getTarget().getClass().getName(), jp.getSignature().getName());
logger.info("INFO:: " + jp.getTarget().getClass().getName() + " " + jp.getSignature().getName() + " Finished:");
return returnVal;
}
mycom 包及其子包下有很多类。一些类是枚举和最终类。 正因为如此,我得到了
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
!within(is(FinalType))
我已经在 pom 文件中添加了这个 maven 依赖
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.8.4</version>
</dependency>
我也添加了这个maven依赖
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.4</version>
</dependency>
现在,一切都像魅力一样运作。任何想法,这里发生了什么?
【问题讨论】:
标签: spring aop aspectj spring-aop