Cobertura and Spring auto proxying
If you are using Cobertrua to get coverage reports, you may run into the error message shown below (lines folded for clarity):
Caused by: org.springframework.beans.factory.BeanCreationException:Specifically if you are using AspectJ auto proxying, like below:
Error creating bean with name 'myBean' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed;
nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type
'$Proxy28 implementing net.sourceforge.cobertura.coveragedata.HasBeenInstrumented, org.springframework.aop.SpringProxy, org.springframework.aop.framework.Advised' to required type 'com.mydomain.MyDao' for property 'myDao';
nested exception is java.lang.IllegalStateException: Cannot convert value of type
[$Proxy28 implementing net.sourceforge.cobertura.coveragedata.HasBeenInstrumented, org.springframework.aop.SpringProxy, org.springframework.aop.framework.Advised] to required type [com.mydomain.MyDao]
for property 'myDao': no matching editors or conversion strategy found
<context:annotation-config/>To fix the issue, just add the following property:
<aop:aspectj-autoproxy/>
<context:annotation-config/>That should fix the exception shown above. To know more about this property please refer to Spring documentation.
<aop:aspectj-autoproxy proxy-target-class="true" />
Comments
The solution was to set the scoped-proxy to targetClass, eg.
I noticed that this seem to happend with tests related to Hibernate, which also has it's own proxing mecanism.
The project we have that uses hibernate gets this problem, the others do not.
"Spring AOP uses either JDK dynamic proxies or CGLIB to create the proxy for a given target object. (JDK dynamic proxies are preferred whenever you have a choice)"
u did a great help :)