Hello,
I'm using @Configurable with <aop:spring-configured/> and org.springframework.aop.framework.autoproxy.Defaul tAdvisorAutoProxyCreator for other issues.
I have a set of Annotations which are intercepted with Spring AOP proxy based, but there are object which are not created from Spring Context. The following snippet code show a little example.
Code:
package test.springdbc.domain;
import org.springdbc.attributes.Precondition;
import org.springframework.beans.factory.annotation.Configurable;
@Configurable
public class Persona {
private String nombre;
private int edad;
public int getEdad() {
return edad;
}
public String getNombre() {
return nombre;
}
@Precondition ("$0 > 18")
public void setEdad(int edad) {
this.edad = edad;
}
@Precondition ("$0 != null")
public void setNombre(String nombre) {
this.nombre = nombre;
}
}
My test
Code:
package test.springdbc;
import org.springframework.test.AbstractSpringContextTests;
import test.springdbc.domain.Persona;
public class PersonaTest extends AbstractSpringContextTests {
public void testPersonaConfiguration() {
Persona p = new Persona();
p.setEdad(20);
assertEquals(20,p.getEdad())
}
protected void setUp() throws Exception {
super.setUp();
getContext(new String[] {
"/application-context.xml"
});
}
}
My application-context look like this
Code:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation=
"http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
<aop:spring-configured/>
<bean id="autoproxy" class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator">
<property name="proxyTargetClass" value="true"/>
</bean>
<!-- <bean id="attributes" class="org.springdbc.interceptor.AnnotationsAttributes"/> -->
<bean id="attributesDbcAttributeSource"
class="org.springdbc.interceptor.AnnotationsDbcAttributeSource"
autowire="constructor">
<property name="checkLevel" value="INVARIANT"></property>
</bean>
<bean id="dbcInterceptor"
class="org.springdbc.interceptor.DbcInterceptor"
autowire="byType">
</bean>
<bean id="dbcAdvisor"
class="org.springdbc.interceptor.DbcAttributeSourceAdvisor"
autowire="constructor"/>
<bean class="test.springdbc.domain.Persona" lazy-init="true"/>
</beans>
My envairoment is using: Spring 2.0r2, aspectjweaver.jar (version 1.5.1a)
My VM argument: -javaagent
ath/aspectjweaver.jar
I have CGLIB in my classpath.
But when I run the test case, I obtain the following exception
Code:
2006-09-08 09:50:35,957 INFO [test.springdbc.PersonaTest] - <Loading config for: /application-context.xml>
weaveinfo Join point 'initialization(void test.springdbc.domain.Persona.<init>())' in Type 'test.springdbc.domain.Persona' (Persona.java:7) advised by afterReturning advice from 'org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect' (AbstractBeanConfigurerAspect.aj:43)
abort trouble in:
public class org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect$$EnhancerByCGLIB$$391cc4fb extends org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect implements org.springframework.aop.framework.Advised, net.sf.cglib.proxy.Factory:
private boolean CGLIB$BOUND
private boolean CGLIB$CONSTRUCTED
private static final ThreadLocal CGLIB$THREAD_CALLBACKS
private static final net.sf.cglib.proxy.Callback[] CGLIB$STATIC_CALLBACKS
private net.sf.cglib.proxy.MethodInterceptor CGLIB$CALLBACK_0
private net.sf.cglib.proxy.MethodInterceptor CGLIB$CALLBACK_1
private net.sf.cglib.proxy.NoOp CGLIB$CALLBACK_2
private net.sf.cglib.proxy.Dispatcher CGLIB$CALLBACK_3
private net.sf.cglib.proxy.Dispatcher CGLIB$CALLBACK_4
private net.sf.cglib.proxy.MethodInterceptor CGLIB$CALLBACK_5
private static final java.lang.reflect.Method CGLIB$ajc$pointcut$$beanCreation$66a$0$Method
private static final net.sf.cglib.proxy.MethodProxy CGLIB$ajc$pointcut$$beanCreation$66a$0$Proxy
private static final Object[] CGLIB$emptyArgs
private static final java.lang.reflect.Method CGLIB$ajc$afterReturning$org_springframework_beans_factory_aspectj_AbstractBeanConfigurerAspect$1$6b4509ab$1$Method
private static final net.sf.cglib.proxy.MethodProxy CGLIB$ajc$afterReturning$org_springframework_beans_factory_aspectj_AbstractBeanConfigurerAspect$1$6b4509ab$1$Proxy
private static final java.lang.reflect.Method CGLIB$ajc$pointcut$$beanCreation$717$2$Method
private static final net.sf.cglib.proxy.MethodProxy CGLIB$ajc$pointcut$$beanCreation$717$2$Proxy
private static final java.lang.reflect.Method CGLIB$destroy$3$Method
private static final net.sf.cglib.proxy.MethodProxy CGLIB$destroy$3$Proxy
private static final java.lang.reflect.Method CGLIB$configureBean$4$Method
private static final net.sf.cglib.proxy.MethodProxy CGLIB$configureBean$4$Proxy
private static final java.lang.reflect.Method CGLIB$setBeanFactory$5$Method
private static final net.sf.cglib.proxy.MethodProxy CGLIB$setBeanFactory$5$Proxy
private static final java.lang.reflect.Method CGLIB$setBeanWiringInfoResolver$6$Method
private static final net.sf.cglib.proxy.MethodProxy CGLIB$setBeanWiringInfoResolver$6$Proxy
private static final java.lang.reflect.Method CGLIB$hashCode$7$Method
private static final net.sf.cglib.proxy.MethodProxy CGLIB$hashCode$7$Proxy
private static final java.lang.reflect.Method CGLIB$clone$9$Method
private static final net.sf.cglib.proxy.MethodProxy CGLIB$clone$9$Proxy
private static final java.lang.reflect.Method CGLIB$equals$10$Method
private static final net.sf.cglib.proxy.MethodProxy CGLIB$equals$10$Proxy
private static final java.lang.reflect.Method CGLIB$toString$11$Method
private static final net.sf.cglib.proxy.MethodProxy CGLIB$toString$11$Proxy
static void CGLIB$STATICHOOK1():
NEW java.lang.ThreadLocal
DUP
INVOKESPECIAL java.lang.ThreadLocal.<init> ()V
PUTSTATIC org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect$$EnhancerByCGLIB$$391cc4fb.CGLIB$THREAD_CALLBACKS Ljava/lang/ThreadLocal;
LDC "org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect$$EnhancerByCGLIB$$391cc4fb"
INVOKESTATIC java.lang.Class.forName (Ljava/lang/String;)Ljava/lang/Class;
DUP
ASTORE_0
INVOKEVIRTUAL java.lang.Class.getClassLoader ()Ljava/lang/ClassLoader;
....
If I remove the CGLIB from my classpath, then the Spring AOP proxy based don't work.
What do you suggest I do?
Thanks
Javier