title: Getting Spring Error "Bean named 'x' must be of type [y], but was actually of type [$Proxy]" in Jenkins
body: <p>I have been debugging this for awhile now, and I'm hoping someone could shed some light here.</p>
  
  <p>I have a Maven project that is added into Jenkins, using JDK 1.6. I'm using AOP in this project to handle the database transaction.</p>
  
  <p>When I run the build in Jenkins, my testcase fails with the following exceptions:-</p>
  
  <pre><code>Caused by: org.springframework.beans.factory.BeanCreationException: 
  Error creating bean with name 'dataHandlerClassificationImpl': 
  Injection of resource dependencies failed; nested exception is 
  org.springframework.beans.factory.BeanNotOfRequiredTypeException: 
  Bean named 'writerDataLocationImpl' must be of type [xxx.script.WriterData], 
  but was actually of type [$Proxy17]
      ...
      ...
  Caused by: org.springframework.beans.factory.BeanNotOfRequiredTypeException: 
  Bean named 'writerDataLocationImpl' must be of type [xxx.script.WriterData], 
  but was actually of type [$Proxy17]
      ...
      ...
  </code></pre>
  
  <p>The <code>DataHandlerClassificationImpl</code> class looks something like this:-</p>
  
  <pre><code>@Service
  public class DataHandlerClassificationImpl extends DataHandler {
  
      @Resource(name="writerDataLocationImpl")
      private WriterData writerData;
  
      ...
  }       
  </code></pre>
  
  <p><code>WriterData</code> is an interface with multiple implementations.</p>
  
  <p>I am able to execute the code without problem from the IDE. To determine whether it is a Maven problem or Jenkins problem, I navigated to the Jenkins' project job folder using command line and I'm able to run <code>mvn test</code> without any errors. </p>
  
  <p>I know the proxy error has something to do with AOP, and that I can only autowire to an interface instead of a concrete class... but that's not the case here since I'm able to run my code fine outside Jenkins.</p>
  
  <p>Any ideas? Thanks.      </p>