0

I'm having issues trying to get MyBatis and Javers (with Spring) integrated and working. I've followed instructions at http://javers.org/documentation/spring-integration/ and gotten the Aspect setup, and annotated my entity class and registered it with Javers, and the MyBatis interface correctly annotated with @Repository and @JaversAuditable on the appropriate methods, but still haven't gotten it to work, even setting breakpoints in the Javers Aspect, but nothing triggers.

I've also gone about it the other way, using MyBatis plugin interceptor, as per http://www.mybatis.org/mybatis-3/configuration.html#plugins (then used http://www.mybatis.org/spring/xref-test/org/mybatis/spring/ExecutorInterceptor.html as a basic example for commits). However while it's triggering, it's not doing what I expected and is basically just an aspect around on the commit method, which takes a boolean rather than containing which entity(ies) are being commited which would let me pass them to Javers. I suppose I could add an interceptor on the update/insert MyBatis methods, and then stored that in a ThreadLocal or similar so that when commit/rollback was called I could pass it to Javers as necessary, but that's messy.

I've got no clue where to go from here, unless someone can see something I've missed with one of those 2 methods.

4

1 回答 1

0

所以在我的困惑中,我意识到由于 MyBatis 为 Mapper Interfaces 生成了具体对象,Spring 似乎从来没有创建该对象,只是将最终对象注册为上下文中的 Bean。因此,Javers 永远没有机会在创建 Bean 时对其进行处理,以便进行任何代理或不必要的操作。

所以,愚蠢的我。所以我最终创建了一个 Spring-Data @Repository 层,它主要只是将调用传递给 Mapper。虽然在更新时我正在做一些额外的位,DAO 垫片层(正如我所说的那样)适用于这些位。

于 2016-03-30T20:39:13.463 回答