OpenSessionInView过滤器导致grails run-app炸弹?

时间:2011-05-10 15:13:57

标签: hibernate spring tomcat grails liferay

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

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>

我尝试添加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>

1 个答案:

答案 0 :(得分:2)

非常奇怪,但您需要在文件顶部添加多个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事件来删除它,但这很痛苦。