Spring data jpa 添加过滤器/拦截器
问题描述:
我之前使用过 hibernate,并成功添加了一个过滤器,可以拦截保存和实现某个接口的实体会记录一些内容.
I have used hibernate before, and have successfully added a filter that would intercept saves and entities who implemented a certain interface would have something logged.
是否可以在新的 Spring Data 中做类似的事情,我刚刚开始使用它.
Is it possible to do something similar in the new Spring Data, I have just started out using it.
答
是的,您始终可以使用 spring 数据添加过滤器/拦截器
Yes you can always add filters/interceptors with spring data
以下是一个例子:
<bean id="customizableTraceInterceptor" class="
org.springframework.aop.interceptor.CustomizableTraceInterceptor">
<property name="enterMessage" value="Entering $[methodName]($[arguments])"/>
<property name="exitMessage" value="Leaving $[methodName](): $[returnValue]"/>
</bean>
<aop:config>
<aop:advisor advice-ref="customizableTraceInterceptor"
pointcut="execution(public * org.springframework.data.jpa.repository.JpaRepository+.*(..))"/>
</aop:config>
参考:http://static.springsource.org/spring-data/data-jpa/docs/current/reference/html/