8

I'm using Spring's <aop:aspectj-autoproxy /> to proxy some JPA repository interfaces.

However, the proxying is failing with the following Cannot subclass final class class $Proxy80:

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

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.

Here's the definition of the interface that's failing:

public interface AuthorDAO extends
    CrossStoreJpaRepository<Author,Long>, CrossStoreQueryDslPredicateExecutor<Author> {

}

Note I'm using a custom subclass of spring's JpaRepository and QueryDslPredicateExecutor, defined as follows:

public interface CrossStoreJpaRepository<T, ID extends Serializable> extends JpaRepository<T, ID> {}
public interface CrossStoreQueryDslPredicateExecutor<T> extends QueryDslPredicateExecutor<T>{}

Elsewhere, I define custom aspects for methods on these interfaces:

@Aspect
@Component
public class DocumentLoadingAspect extends AbstractDocumentAspect {

    @Around("execution(* com.mangofactory.crossstore.repository.CrossStore*.find*(..))")
    public Object loadCrossStoreEntity(ProceedingJoinPoint pjp) throws Throwable
    {
         // implementation omitted
    }

I've confirmed that it's these @Aspect definitions that are causing the problem by removing them and re-running the app.

What is causing this error? It seems to be that proxying a proxy is failing for some reason.

Marty Pitt
  • 28,822
  • 36
  • 122
  • 195
  • Did you find the solution for this? I'm getting the same error when on the Integration Gateway interface. – Ocelot Dec 02 '15 at 04:32

1 Answers1

0

My guess is that Spring data JPA creates the repo implementation as a Java proxy which is final and then <aop:aspectj-autoproxy /> attempts to to create another proxy per your aspect using cglib subclassing which won't work. Is proxy-target-class set to true on the autoproxy element?

Jukka
  • 4,583
  • 18
  • 14