|
From: Wenke J. <ji...@gm...> - 2008-12-03 13:01:32
|
Hi,
In the usage of the AOP , we found that with the proxy class usign CGLIB
with contructor arg - a exception throw with
"org.springframework.aop.framework.AopConfigException". Checking the source
code and the testcases(Version 2.5.6) and found that Spring actually doesn't
support it. Is that means Spring not encourage this use cases or it is a
missing functionality? - it sounds tricky, can any one help to clarify it ?
Thanks your time so much!
Tracing code in the Cglib2AopProxy line197:
if (this.constructorArgs != null) {
proxy = enhancer.create(this.constructorArgTypes,
this.constructorArgs);
}
else {
proxy = enhancer.create();
}
it is the exception occurred.
And by trace the use of the Cglib2AopProxy.setConstructorArguments - It is
only called in the testcases instead of production code. Does it means when
use don't permit to AOP those class with arg constructor directly?
public void testWithNoArgConstructor() {
1. NoArgCtorTestBean target = new NoArgCtorTestBean("b", 1);
2. target.reset();
3.
4. mockTargetSource.setTarget(target);
5. AdvisedSupport pc = new AdvisedSupport(new Class[]{});
6. pc.setTargetSource(mockTargetSource);
7. Cglib2AopProxy aop = new Cglib2AopProxy(pc);
8. aop.setConstructorArguments(new Object[] {"Rob Harrop", new
Integer(22)},
9. new Class[] {String.class, int.class});
10. NoArgCtorTestBean proxy = (NoArgCtorTestBean) aop.getProxy();
11. proxy = (NoArgCtorTestBean) aop.getProxy();
12.
13. assertNotNull("Proxy should be null", proxy);
14. }
|