I am using try to implement Logging using Spring AOP. I have defined the
@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;
}
There are lot of classes under mycom package and its subpackages. Some of the classes are enum and final class. Because of this I am getting
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)
Is there a way to exclude all the final classes and enum classes from logging using some kind of regular expression. Note:I have enum classes all over in different packages. It would be difficult to exclude them using complete class names.
Update 2014-11-17 (trying kriegaex's solution):
I tried using
@Pointcut("!within(is(FinalType))")
but I am getting following error
Pointcut is not well-formed: expecting ')' at character position 10
!within(is(FinalType))
I have added this maven dependency in the pom file
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.8.4</version>
</dependency>
I have also added this maven dependency
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.4</version>
</dependency>
Now, everything is working like charm. Any ideas, whats happening here?