在Java配置中使用OpenSessionInViewInterceptor而不是WebXML
我已经看到了很多添加在Java配置中使用OpenSessionInViewInterceptor而不是WebXML,java,spring,hibernate,Java,Spring,Hibernate,我已经看到了很多添加OpenSessionInViewFilter和OpenSessionInViewInterceptor的例子,看来拦截器是我需要的方式。我的应用程序是使用Java配置而不是web.xml样式的配置设置的 在我的WebMVCConfigureAdapter中,我正在设置拦截器: @Bean public OpenSessionInViewInterceptor openSessionInViewInterceptor(){ OpenSessionInViewInter
OpenSessionInViewFilter
和OpenSessionInViewInterceptor
的例子,看来拦截器是我需要的方式。我的应用程序是使用Java配置而不是web.xml样式的配置设置的
在我的WebMVCConfigureAdapter
中,我正在设置拦截器:
@Bean
public OpenSessionInViewInterceptor openSessionInViewInterceptor(){
OpenSessionInViewInterceptor openSessionInViewInterceptor = new OpenSessionInViewInterceptor();
openSessionInViewInterceptor.setSessionFactory(sessionFactory);
return openSessionInViewInterceptor;
}
这看起来不错,但问题是如何将其连接到Spring配置中
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addWebRequestInterceptor(openSessionInViewInterceptor());
super.addInterceptors(registry);
}
尝试此操作后,它编译并运行得很好,但我仍然遇到无法初始化代理-前端没有会话错误。它是否真的像我希望的那样通过这个函数连接,或者是否有其他(更正确的)方法来添加这个拦截器
是否有人在JavaSpring配置中配置了这种OpenSessionInviewWinterCeptor
?提前谢谢。请发布堆栈跟踪。您看到的是非常过时的文档。@SotiriosDelimanolis编译了它,但仍然获得会话无法初始化代理-没有会话错误。要将代码块更新为当前代码块,请尝试更新问题。