OpenSessionInView 过滤器导致 grails run-app 崩溃?

发布于 2024-11-06 05:26:36 字数 1534 浏览 0 评论 0原文

我使用 OpenSessionInView 和 DWR 来为我的 ajax 请求获取休眠会话。当我开始部署战争时,这工作正常,但是当我尝试使用 run-app 运行时,我收到以下错误:

ERROR: org.apache.catalina.startup.ContextConfig -文件中的应用程序 web.xml 文件中的解析错误:/C:/Users/stefan/.grails/1.3.6/projects/myproject/resources/web.xml java.lang.IllegalArgumentException:过滤器映射指定未知的过滤器名称hiddenHttpMethod

web.xml

<filter>
    <filter-name>hibernateFilter</filter-name>
    <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
    <init-param>
        <param-name>singleSession</param-name>
        <param-value>true</param-value>
    </init-param>
</filter>

<filter-mapping>
    <filter-name>hibernateFilter</filter-name>
    <url-pattern>/dwr/*</url-pattern>
</filter-mapping>

我尝试添加hiddenHttpMethod过滤器映射,但出现相同的错误。这是怎么回事?

添加失败的条目:

<filter>
        <filter-name>hiddenHttpMethod</filter-name>
        <filter-class>org.codehaus.groovy.grails.web.filters.HiddenHttpMethodFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>hiddenHttpMethod</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>FORWARD</dispatcher>
        <dispatcher>REQUEST</dispatcher>
    </filter-mapping>

I'm using OpenSessionInView with DWR to get a hibernate session for my ajax requests. This works fine when I start through a deployed war, but when I try to run with run-app, I get the following error:

ERROR: org.apache.catalina.startup.ContextConfig - Parse error in application web.xml file at file:/C:/Users/stefan/.grails/1.3.6/projects/myproject/resources/web.xml
java.lang.IllegalArgumentException: Filter mapping specifies an unknown filter name hiddenHttpMethod

web.xml

<filter>
    <filter-name>hibernateFilter</filter-name>
    <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
    <init-param>
        <param-name>singleSession</param-name>
        <param-value>true</param-value>
    </init-param>
</filter>

<filter-mapping>
    <filter-name>hibernateFilter</filter-name>
    <url-pattern>/dwr/*</url-pattern>
</filter-mapping>

I tried adding the hiddenHttpMethod filter mapping, but I get the same error. What's going on?

Added entries which failed:

<filter>
        <filter-name>hiddenHttpMethod</filter-name>
        <filter-class>org.codehaus.groovy.grails.web.filters.HiddenHttpMethodFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>hiddenHttpMethod</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>FORWARD</dispatcher>
        <dispatcher>REQUEST</dispatcher>
    </filter-mapping>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独孤求败 2024-11-13 05:26:36

很奇怪,但是您需要将多个 web.xml 条目添加到文件顶部,因为过滤器顺序很重要。

将其添加到过滤器顶部附近:

 <filter>
        <filter-name>hiddenHttpMethod</filter-name>
        <filter-class>org.codehaus.groovy.grails.web.filters.HiddenHttpMethodFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>hiddenHttpMethod</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>FORWARD</dispatcher>
        <dispatcher>REQUEST</dispatcher>
    </filter-mapping>

    <filter>
        <filter-name>reloadFilter</filter-name>
        <filter-class>org.codehaus.groovy.grails.web.servlet.filter.GrailsReloadServletFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>reloadFilter</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>FORWARD</dispatcher>
        <dispatcher>REQUEST</dispatcher>
    </filter-mapping>

但是请注意,这会将 reloadFilter 添加到您的生产战争中。您可以通过拦截 webXml 事件来删除它,但这很痛苦。

Very odd, but you need to add multiple web.xml entries to the top of the file, as the filter order is important.

Add this near the top of your filters:

 <filter>
        <filter-name>hiddenHttpMethod</filter-name>
        <filter-class>org.codehaus.groovy.grails.web.filters.HiddenHttpMethodFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>hiddenHttpMethod</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>FORWARD</dispatcher>
        <dispatcher>REQUEST</dispatcher>
    </filter-mapping>

    <filter>
        <filter-name>reloadFilter</filter-name>
        <filter-class>org.codehaus.groovy.grails.web.servlet.filter.GrailsReloadServletFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>reloadFilter</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>FORWARD</dispatcher>
        <dispatcher>REQUEST</dispatcher>
    </filter-mapping>

Note, however, that this adds the reloadFilter to your production war. You can remove this by intercepting the webXml events, but that's a pain.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文