Spring数据jpa添加过滤器/拦截器

时间:2012-10-10 16:31:52

标签: spring spring-data spring-data-jpa

之前我使用过hibernate,并成功添加了一个拦截保存的过滤器,实现某个界面的实体会记录一些内容。

是否有可能在新的Spring Data中做类似的事情,我刚刚开始使用它。

1 个答案:

答案 0 :(得分:5)

是的,您始终可以使用弹簧数据添加过滤器/拦截器

以下是一个例子:

<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/

相关问题