Spring AspectJ fails when using the dual proxy interface: failed to subclass CGLIB class

I am using Spring <aop:aspectj-autoproxy /> to proxy some interfaces of the JPA repository .

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

Failed to subclass CGLIB class class [class $ Proxy80]: Common causes of this problem include the use of a finite class or an invisible class; The nested exception is java.lang.IllegalArgumentException: Can not subclass class final class $ Proxy80

Like a bug, as well as a quick google, this suggests that this means that the target of the proxy is the final class. However, there are no classes in this chain — only interfaces. Spring generates all implementations at runtime.

Here is the definition of an interface that does not work:

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

Note. I use my own subclass of Spring 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 user-specific aspects of 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 have confirmed that these are @Aspect definitions that cause the problem by deleting them and restarting the application.

What causes this error? It seems that the proxy server of the proxy server for some reason does not work.

+8
java spring aspectj
source share
1 answer

My guess is that the Spring JPA file creates the repo implementation as a Java proxy, which is final , and then <aop:aspectj-autoproxy /> tries to create another proxy for your aspect using the cglib subclass, that works . Is proxy-target-class to true in the autoproxy element?

0
source share

All Articles