当双代理接口时,Spring AspectJ失败:无法生成类的CGLIB子类
我正在使用Spring的来代理一些JPA存储库接口。
但是,代理失败,以下内容Cannot subclass final class class $Proxy80
:
无法生成类[class $ Proxy80]的CGLIB子类:此问题的常见原因包括使用最终类或不可见类; 嵌套exception是java.lang.IllegalArgumentException:不能inheritance最终类class $ Proxy80
由于错误和快速谷歌建议 – 当代理目标是最终类时会发生这种情况。 但是,在这个链中,没有类 – 只有接口。 Spring在运行时生成所有实现。
这是失败的接口的定义:
public interface AuthorDAO extends CrossStoreJpaRepository, CrossStoreQueryDslPredicateExecutor { }
注意我正在使用spring的JpaRepository和QueryDslPredicateExecutor的自定义子类,定义如下:
public interface CrossStoreJpaRepository extends JpaRepository {} public interface CrossStoreQueryDslPredicateExecutor extends QueryDslPredicateExecutor{}
在其他地方,我在这些接口上定义方法的自定义方面:
@Aspect @Component public class DocumentLoadingAspect extends AbstractDocumentAspect { @Around("execution(* com.mangofactory.crossstore.repository.CrossStore*.find*(..))") public Object loadCrossStoreEntity(ProceedingJoinPoint pjp) throws Throwable { // implementation omitted }
我已经确认这些@Aspect
定义通过删除它们并重新运行应用程序来导致问题。
导致此错误的原因是什么? 似乎代理代理由于某种原因失败了。
我的猜测是,Spring数据JPA将repo实现创建为最终的Java代理,然后
尝试使用cglib子类创建另一个代理,这将无效。 在autoproxy元素上, proxy-target-class
设置为true
?