Spring AspectJ fails when double-proxying interface: Could not generate CGLIB subclass of class

萝らか妹 提交于 2019-12-09 11:38:00

问题


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.


回答1:


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?



来源:https://stackoverflow.com/questions/10377704/spring-aspectj-fails-when-double-proxying-interface-could-not-generate-cglib-su

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!