0

Springアプリケーションでは、org.springframework.web.filter.ShallowEtagHeaderFilterを使用してETagを追加します。本当に大きなデータを出力する場合を除いて、これはうまく機能します。次に、アプリケーションのメモリが不足し、JVMが終了します。フィルタを削除すると、すべてがうまく機能します。

しかし、私はETagを使用するのが本当に好きなので、いくつかのURLマッピングを除いてサーブレット全体をフィルタリングするフィルター定義をweb.xmlで作成するにはどうすればよいですか?私のフィルターは現時点では次のようになっています。

<filter> 
    <filter-name>etagFilter</filter-name> 
    <filter-class>org.springframework.web.filter.ShallowEtagHeaderFilter</filter-class> 
</filter> 

<filter-mapping> 
    <filter-name>etagFilter</filter-name> 
    <servlet-name>MyWebApp</servlet-name>
</filter-mapping>

乾杯

ニック

4

2 に答える 2

3

宣言的にそれを行う方法はありません。doFilter()それをオーバーライドして、リクエストのプロパティに基づいてプログラムで決定を下す必要があると思います。

于 2011-03-21T12:36:53.983 に答える
1

OncePerRequestFilterには、これを行うためにオーバーライドできるshouldNotFilter()というメソッドがあります。

私はいくつかのフィルターに対して同様のことをしています。以下にサンプルのweb.xmlフラグメントを示します。

<filter>
    <filter-name>hibernateFilter</filter-name>
    <filter-class>com.xyz.config.OpenSessionInViewFilter</filter-class>
    <init-param>
        <param-name>excludePaths</param-name>
        <param-value>/js:/log/</param-value>
    </init-param>
</filter>

そして、フィルターは次のとおりです。

class OpenSessionInViewFilter extends org.springframework.orm.hibernate3.support.OpenSessionInViewFilter {
  @BeanProperty var excludePaths: String = null
  val excludePathList = new mutable.ArrayBuffer[String]

  override def initFilterBean {
    if (excludePaths != null) {
      excludePaths.split(':').foreach(excludePathList += _)
    }
    super.initFilterBean
  }

  override def shouldNotFilter(request: HttpServletRequest) = {
    val httpServletRequest = request.asInstanceOf[HttpServletRequest]
    val servletPathInfo = httpServletRequest.getServletPath + httpServletRequest.getPathInfo
    excludePathList.exists(p => servletPathInfo.startsWith(p)) || DataConfig.noDB
  }

}

于 2011-03-21T13:32:30.830 に答える