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