Back Forum Reply New

Problem with AOP Advisor and Tomcat

Hi, I'm using Spring 2.0 and Tomcat 5.5.17.

I'm trying to create a Throws advice. I've created my Advice class and added the following configuration in my context configuration file: lt;bean id=quot;exceptionTransformationAdvicequot; class=quot;ExceptionTransformationAdvicequot;/gt; lt;bean id=quot;exceptionTransformationAdvisorquot; class=quot;org..aop.support.NameMatchMe  thodPointcutAdvisorquot;gt;   lt;property name=quot;mappedNamequot;gt;     lt;valuegt;*lt;/valuegt;   lt;/propertygt;   lt;property name=quot;advicequot;gt;     lt;ref bean=quot;exceptionTransformationAdvicequot;/gt;   lt;/propertygt; lt;/beangt;

At this point I would expect the Advisor just to be defined but not yet working, as I've not attached it to a Proxy. My plan was adding it to the BeanNameAutoProxyCreator as follows:
lt;bean id=quot;autoProxyCreatorquot; class=quot;org..aop.framework.autoproxy  .BeanNameAutoProxyCreatorquot;gt;   lt;property name=quot;interceptorNamesquot;gt;     lt;listgt;       .... other interceptors here ....       lt;valuegt;exceptionTransformationAdvisorlt;/valuegt;     lt;/listgt;   lt;/propertygt;   lt;property name=quot;beanNamesquot;gt;     lt;listgt;       lt;valuegt;*ServiceManagerlt;/valuegt;     lt;/listgt;   lt;/propertygt;   lt;property name=quot;proxyTargetClassquot; value=quot;truequot; /gt;   lt;property name=quot;orderquot; value=quot;1quot; /gt; lt;/beangt;

But, even before I add it to the auto proxy creator, just by having the Advisor defined, Tomcat fails to start with a CGLIB error as follows. Notice that the authenticationEventListenerNAS is a simple event listener that is not related whatsoever to this Advisor:

ERROR context.ContextLoader.initWebApplicationContext() - Context initialization failed
org..beans.factory.BeanCreationExce  ption: Error creating bean with name 'authenticationEventListenerNAS' defined in S
ervletContext resource [/WEB-INF/applicationContext-acegi-security.xml]: Initialization of bean failed; nested exception is org.spri
ngframework.aop.framework.AopConfigException: Couldn't generate CGLIB subclass of class [class org.apache.tomcat.dbcp.dbcp.BasicData
Source]: Common causes of this problem include using a final class or a non-visible class; nested exception is net.sf.cglib.core.Cod
eGenerationException: java.lang.reflect.InvocationTargetException--gt;null
Caused by:
org..aop.framework.AopConfigExcepti  on: Couldn't generate CGLIB subclass of class [class org.apache.tomcat.dbcp.dbcp.B
asicDataSource]: Common causes of this problem include using a final class or a non-visible class; nested exception is net.sf.cglib.
core.CodeGenerationException: java.lang.reflect.InvocationTargetException--gt;null
Caused by:
net.sf.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException--gt;null       at net.sf.cglib.core.AbstractClassGenerator.create(Ab  stractClassGenerator.java:237)       at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.  java:377)

and then, the source of the problem:       at net.sf.cglib.core.AbstractClassGenerator.create(Ab  stractClassGenerator.java:219)       ... 54 more
Caused by: java.lang.NoClassDefFoundError: org//aop/framework/Advised       at java.lang.ClassLoader.defineClass1(Native Method)       at java.lang.ClassLoader.defineClass(ClassLoader.java  :620)       ... 60 more

The error is produced because the Spring libraries are not available to Tomcat (they are available to my WAR in its WEB-INF/lib directory) and it seems  that CGLIB is trying to create a proxy of org.apache.tomcat.dbcp.dbcp.BasicDataSource !!??

I don't understand why CGLIB would try to do this. As far as I know Tomcat's BasicDataSource has nothing to do with my Spring beans and in any case the Advisor has not even been attached to any proxy.

Does anybody have any ideas/suggestions?

I found the issue. The problem was produced because I was using Spring AspectJ and Spring AOP at the same time.
Before I only used Spring AspectJ but I could not create an aspect with @AfterThrowing with format:   @AfterThrowing(       pointcut=lt;pointcut heregt;,       throwing=quot;equot;)

Because the throwing bit required ASM 2.x. I use Hibernate as well, but it has a dependency on ASM 1.5.3 through CGLIB. Therefore I decided to implement an Spring AOP ThrowsAdvice instead (and leave my other aspects as Spring AspectJ). Both kind of approaches living together seem to give problems.

The issue seems to be that as soon as I add the Spring Advisor (even before I weave it to any bean), the AspectJ entry:   lt;aop:aspectj-autoproxy proxy-target-class=quot;truequot; /gt;
seems to go crazy and tries to proxy things that it shouldn't.

My advise, use one or the other, but not both at the same time. I'll have to stick with Spring AOP until Hibernate updates its CGLIB version to the latest one which uses the right version of ASM.
¥
Back Forum Reply New