Spring Boot 2.0.0 M6 - Add Hibernate Interceptor

走远了吗. 提交于 2019-11-30 21:32:06

Hello,

Give this a read: https://github.com/spring-projects/spring-boot/commit/59d5ed58428d8cb6c6d9fb723d0e334fe3e7d9be (use: HibernatePropertiesCustomizer interface)

  1. Implement it.
  2. @Override customize() method, add your interceptor
  3. Don't forget to @Lazy inject in case of internal beans
  4. Done => Run

Hope this was of use to you.

As a final note: always update your Spring / Hibernate versions (use the latest as possible) and you will see that most code will become redundant as newer versions try to reduce the configurations as much as possible.

As https://github.com/spring-projects/spring-boot/issues/11211 has been resolved, HibernatePropertiesCustomizer can be used since Spring Boot 2.0.0.RC1 (not released at the moment of writing yet but snapshots are available now).

I can solve this with this documentation:

Add support for advanced customization of Hibernate settings

Just implements a interface HibernatePropertiesCustomizer

and implements methods customize(Map hibernateProperties)

@Component
class MyHibernateInterceptorCustomizer implements HibernatePropertiesCustomizer {

@Autowired
MyInterceptor myInterceptor

@Override
    @Override
    void customize(Map<String, Object> hibernateProperties) {
       hibernateProperties.put("hibernate.session_factory.interceptor", myInterceptor);
    }

}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!