集成测试中如何触发Hibernate拦截器?
我已经为 boolean onFlushDirty
方法创建了拦截器。
注册它就像
@Component
public class HibernateInterceptorRegistration implements HibernatePropertiesCustomizer {
// My interceptor
private final EntityInterceptor entityInterceptor;
public HibernateInterceptorRegistration(EntityInterceptor entityInterceptor) {
this.entityInterceptor = entityInterceptor;
}
@Override
public void customize(Map<String, Object> hibernateProperties) {
hibernateProperties.put("hibernate.session_factory.interceptor", entityInterceptor);
}
}
应用程序工作正常一样,但我无法在集成测试中触发此拦截器。 我有 TestConfig 类,我 @Import
到集成测试类。
我在那里添加了 2 个豆子:
@Bean
public HibernatePropertiesCustomizer hibernatePropertiesCustomizer() {
return new HibernateInterceptorRegistration(entityInterceptor());
}
@Bean
public EntityInterceptor entityInterceptor() {
return new EntityInterceptor();
}
没有任何帮助。在测试中使用拦截器应该怎么做?
I have created interceptor for boolean onFlushDirty
method.
Registered it like that
@Component
public class HibernateInterceptorRegistration implements HibernatePropertiesCustomizer {
// My interceptor
private final EntityInterceptor entityInterceptor;
public HibernateInterceptorRegistration(EntityInterceptor entityInterceptor) {
this.entityInterceptor = entityInterceptor;
}
@Override
public void customize(Map<String, Object> hibernateProperties) {
hibernateProperties.put("hibernate.session_factory.interceptor", entityInterceptor);
}
}
Application works correct, but I cannot trigger this interceptor in integrational test.
I have TestConfig class, that I @Import
to the integrational test class.
There I've added 2 beans:
@Bean
public HibernatePropertiesCustomizer hibernatePropertiesCustomizer() {
return new HibernateInterceptorRegistration(entityInterceptor());
}
@Bean
public EntityInterceptor entityInterceptor() {
return new EntityInterceptor();
}
Nothing helped. What should I do to use interceptor in tests?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论