title: Spring AspectJ fails when double-proxying interface: Could not generate CGLIB subclass of class
body: <p>I'm using Spring's <code>&lt;aop:aspectj-autoproxy  /&gt;</code> to proxy some <a href="http://www.springsource.org/spring-data/jpa" rel="noreferrer">JPA repository</a> interfaces.</p>
  
  <p>However, the proxying is failing with the following <code>Cannot subclass final class class $Proxy80</code>:</p>
  
  <blockquote>
    <p>Could not generate CGLIB subclass of class [class $Proxy80]: 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 $Proxy80</p>
  </blockquote>
  
  <p>As the error, and a quick google, suggests - this occurs when the proxy target is a final class.  However, in this chain, there are no classes - only interfaces.  Spring generates all the implementations at runtime.</p>
  
  <p>Here's the definition of the interface that's failing:</p>
  
  <pre><code>public interface AuthorDAO extends
      CrossStoreJpaRepository&lt;Author,Long&gt;, CrossStoreQueryDslPredicateExecutor&lt;Author&gt; {
  
  }
  </code></pre>
  
  <p>Note I'm using a custom subclass of spring's <a href="http://static.springsource.org/spring-data/data-jpa/docs/current/api/org/springframework/data/jpa/repository/JpaRepository.html" rel="noreferrer">JpaRepository</a> and <a href="http://static.springsource.org/spring-data/data-commons/docs/1.1.0.RELEASE/api/org/springframework/data/querydsl/QueryDslPredicateExecutor.html?is-external=true" rel="noreferrer">QueryDslPredicateExecutor</a>, defined as follows:</p>
  
  <pre><code>public interface CrossStoreJpaRepository&lt;T, ID extends Serializable&gt; extends JpaRepository&lt;T, ID&gt; {}
  public interface CrossStoreQueryDslPredicateExecutor&lt;T&gt; extends QueryDslPredicateExecutor&lt;T&gt;{}
  </code></pre>
  
  <p>Elsewhere, I define custom aspects for methods on these interfaces:</p>
  
  <pre><code>@Aspect
  @Component
  public class DocumentLoadingAspect extends AbstractDocumentAspect {
  
      @Around("execution(* com.mangofactory.crossstore.repository.CrossStore*.find*(..))")
      public Object loadCrossStoreEntity(ProceedingJoinPoint pjp) throws Throwable
      {
           // implementation omitted
      }
  </code></pre>
  
  <p>I've confirmed that it's these <code>@Aspect</code> definitions that are causing the problem by removing them and re-running the app.</p>
  
  <p>What is causing this error?  It seems to be that proxying a proxy is failing for some reason.</p>