title: Spring @Autowired fails in case of Cobertura instrumented class
body: <h3>Question</h3>
  
  <p>Cobertura instrumentation is breaking springs autowiring in a specific case. Does anyone know how to resolve this?</p>
  
  <h3>Scenario</h3>
  
  <ul>
  <li>I am running MVN 3.0.4 with the cobertura-maven-plugin version 2.5.1.</li>
  <li>mvn test runs without issues</li>
  <li>mvn compile, package etc also runs without issues.</li>
  <li>mvn cobertura:cobertura also ran without any issues up until the addition of 2 new features which introduced a number of new classes, including two new com.mycompany.executor executor classes.  (Example: MyHappyExecutor and MySadExecutor was added in addition to the existing MyExecutor)</li>
  <li>Excluding MyExecutor from the cobertura instrumentation process seems to fix autowiring</li>
  <li>Checking the spring autowiring output confirms that the correct beans are getting autowired.</li>
  </ul>
  
  <h3>Point of failure</h3>
  
  <p>Autowiring fails when attempting to autowire the instrumented version of myExecutor in myService. This worked fine before adding MyHappyExecutor and MySadExecutor. MyHappyExecutor and MySadExecutor are autowired and used in MyExecutor exclusively.</p>
  
  <p>I have attached the exception output below. Please not that class and package names have been edited.</p>
  
  <pre><code>Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myService': Injection of autowired dependencies failed; 
  nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.mycompany.executor.MyExecutor com.mycompany.service.impl.MyServiceImpl.myExecutor; 
  nested exception is java.lang.IllegalArgumentException: Can not set com.mycompany.executor.MyExecutor field com.mycompany.service.impl.MyServiceImpl.myExecutor to $Proxy20
  </code></pre>
  
  <h3>Conclusion</h3>
  
  <p>Something in the Cobertura instrumentation process messes up Springs autowiring.</p>
  
  <h3>Update 1</h3>
  
  <p>Forcing CGLIB class proxies changes the error type to a "java.lang.NoClassDefFoundError" error. This is affects the standard test goal as well as the Cobertura goal. </p>
  
  <pre><code>&lt;aop:config proxy-target-class="true"/&gt;
  </code></pre>
  
  <h3>Update 2</h3>
  
  <p>Here is the output from springs startup process for the 3 classes in question.</p>
  
  <pre><code>2012-11-01 16:21:51 INFO  [main] Overriding bean definition for bean 'myExecutor': replacing [Generic bean: class [com.mycompany.executor.MyExecutor]; scope=; abstract=false; lazyInit=false; autowireMode=1; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in class path resource [configuration.xml]] with [Generic bean: class [com.mycompany.executor.MyExecutor]; scope=; abstract=false; lazyInit=false; autowireMode=1; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in class path resource [configuration.xml]] - (DefaultListableBeanFactory.java:623)
  2012-11-01 16:21:51 INFO  [main] Overriding bean definition for bean 'happyExecutor': replacing [Generic bean: class [com.mycompany.executor.HappyExecutor]; scope=; abstract=false; lazyInit=false; autowireMode=1; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in class path resource [configuration.xml]] with [Generic bean: class [com.mycompany.executor.HappyExecutor]; scope=; abstract=false; lazyInit=false; autowireMode=1; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in class path resource [configuration.xml]] - (DefaultListableBeanFactory.java:623)
  2012-11-01 16:21:51 INFO  [main] Overriding bean definition for bean 'sadExecutor': replacing [Generic bean: class [com.mycompany.executor.SadExecutor]; scope=; abstract=false; lazyInit=false; autowireMode=1; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in class path resource [configuration.xml]] with [Generic bean: class [com.mycompany.executor.SadExecutor]; scope=; abstract=false; lazyInit=false; autowireMode=1; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in class path resource [configuration.xml]] - (DefaultListableBeanFactory.java:623)
  </code></pre>