开发者

OpenSessionInView filter causes grails run-app to bomb?

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>


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜