Grails - OSIV - 停止“在视图中打开会话”筛选静态资源 [英] Grails - OSIV - Stop "Open Session In View" filter for Static Resources

查看:114
本文介绍了Grails - OSIV - 停止“在视图中打开会话”筛选静态资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我交叉发布在 Javaranch 太。我通过Google搜索进行了尽职调查。我们没有找到任何答案。



我们有一个REST服务基础Web应用程序,后端使用Groovy和Grails(1.3.7和Groovy 1.7.x) 。我理解Open Session In View在Hibernate中的工作原理,以及在Spring中配置Hibernate时,我们可以指定OSIV应该在过滤器配置中工作的URL集合。



问题是我找不到如何从OSIV过滤器的范围中排除一组URL(如匹配* .js,* .gif等)。我从Hibernate日志中发现,即使对于JavaScript文件请求,Open Session In View也会启动并打开一个会话并关闭它。

预先感谢。

解决方案

Grails有两个OSIV模式的实现, GrailsOpenSessionInViewFilter GrailsOpenSessionInViewInterceptor 。该过滤器用于早期版本的Grails,但拦截器现在用于(至少在1.2,1.3和2.0)。由于它是一个 WebRequestInterceptor ,它仅适用于控制器请求,而不适用于JavaScript,CSS,图像等的静态请求。因此,不必为Hibernate会话创建和绑定简单的文件请求。


I cross-posted in Javaranch too. I did my due diligence by doing Google search. I did not find any answer.

We have a REST service bases Web Application, for which backend is implemented using Groovy and Grails (1.3.7 with Groovy 1.7.x). I understand how Open Session In View works in general for Hibernate, and when configuring Hibernate with Spring, we could specify for which set of URLs, OSIV should work in the filter configuration.

The issue is I cannot find how to exclude a set of URLs from the scope of OSIV filter (like matching *.js, *.gif, etc). I found from the Hibernate log, that even for Javascript file request, Open Session In View kicks in and opens a session and closes it.

Thanks in advance.

解决方案

Grails has two implementations of the OSIV pattern, GrailsOpenSessionInViewFilter and GrailsOpenSessionInViewInterceptor. The filter was used in earlier versions of Grails but the interceptor is now what is used (at least in 1.2, 1.3 and 2.0). Since it's a WebRequestInterceptor it only applies to controller requests and not static requests for JavaScript, CSS, images, etc. So there's no performance concern for unnecessarily creating and binding a Hibernate session for simple file requests.

这篇关于Grails - OSIV - 停止“在视图中打开会话”筛选静态资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆