我希望在运行时向会话或会话工厂添加一个拦截器。我设法用事件处理程序做这样的事情:
@Component
public class HibernateEventListenersRegisterer {
/** The post load event listener. */
@Resource
private GenericPostLoadEventListener postLoadEventListener;
/** The session factory. */
@Resource
private SessionFactory sessionFactory;
/**
* Register all event listeners.
*/
@PostConstruct
public void registerEventListeners() {
EventListenerRegistry registry = ((SessionFactoryImpl) sessionFactory).getServiceRegistry()
.getService(EventListenerRegistry.class);
registry.getEventListenerGroup(EventType.POST_LOAD).appendListener(postLoadEventListener);
}
}
我想以同样的方式使用拦截器……可以吗?