title: Cglib proxy errors using and Spring Data when moving from Spring XD M5 to Release 1.0.0
body: <p>We're moving a number of batch jobs from Spring XD M5 to the 1.0.0 release.</p>
  
  <p>When creating and deploying the jobs, we are hitting an issue with cglib proxy functionality when autowiring Spring Data repositories (for Neo4J in this case).</p>
  
  <p>The tail end of the stack trace:</p>
  
  <pre><code>Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'datasetRepository': Post-processing of FactoryBean's singleton object failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class
   com.sun.proxy.$Proxy112]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Cannot subclass final class class com.sun.proxy.$Proxy112
          at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:116)
          at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1512)
          at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:313)
          at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
          at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1017)
          at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:960)
          at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:858)
          at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:480)
          ... 54 more
  Caused by: org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class com.sun.proxy.$Proxy112]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Cannot subclass final
   class class com.sun.proxy.$Proxy112
          at org.springframework.aop.framework.CglibAopProxy.getProxy(CglibAopProxy.java:212)
          at org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:109)
          at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.createProxy(AbstractAutoProxyCreator.java:494)
          at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:379)
          at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:339)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:421)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.postProcessObjectFromFactoryBean(AbstractAutowireCapableBeanFactory.java:1698)
          at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:113)
          ... 61 more
  Caused by: java.lang.IllegalArgumentException: Cannot subclass final class class com.sun.proxy.$Proxy112
          at org.springframework.cglib.proxy.Enhancer.generateClass(Enhancer.java:446)
          at org.springframework.cglib.transform.TransformingClassGenerator.generateClass(TransformingClassGenerator.java:33)
          at org.springframework.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
          at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216)
          at org.springframework.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
          at org.springframework.cglib.proxy.Enhancer.createClass(Enhancer.java:317)
          at org.springframework.aop.framework.ObjenesisCglibAopProxy.createProxyClassAndInstance(ObjenesisCglibAopProxy.java:57)
          at org.springframework.aop.framework.CglibAopProxy.getProxy(CglibAopProxy.java:202)
          ... 68 more
  </code></pre>
  
  <p>The Spring Data repository interface is annotated with <code>@Repository</code> as follows:</p>
  
  <pre class="lang-java prettyprint-override"><code>@Repository
  public interface DatasetRepository extends GraphRepository&lt;Dataset&gt; 
  {
      public Dataset findOneById(String id);
      public Dataset findOneByName(String name);
  }
  </code></pre>
  
  <p>And the corresponding autowired attribute in our bean class which triggers the exception:</p>
  
  <pre class="lang-java prettyprint-override"><code>    @Autowired
      private DatasetRepository datasetRepo;
  </code></pre>
  
  <p>The bean itself is defined in our XD job XML as follows:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;bean id="myBean" class="com.mycompany.MyBean"/&gt;
  </code></pre>
  
  <p>And the configuration bean (component scanned in the job cfg XML):</p>
  
  <pre class="lang-java prettyprint-override"><code>@Configuration
  @EnableNeo4jRepositories({ "com.mycompany.repositories" })
  public class CustomNeo4jConfiguration implements InitializingBean
  </code></pre>
  
  <p>The versions of Spring Data Neo4J which we deploy into the XD lib folder are as follows:</p>
  
  <pre><code>spring-data-neo4j      : 3.2.0.RELEASE
  spring-data-neo4j-rest : 3.2.0.RELEASE
  </code></pre>
  
  <p>The setup is all on a dev PC (for now) with XD running in distributed mode:</p>
  
  <ul>
  <li>redis server</li>
  <li>Zookeeper server (1x)</li>
  <li>Oracle job repository (local XE instance for now)</li>
  <li>1x admin and 1x container</li>
  </ul>
  
  <p>Any help around configuration of the job, Spring Data repository or XD container would be much appreciated.</p>
  
  <p>Thanks</p>