首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> Java 程式設計 >> Java 綜合教學

Struts 2.3.31+ 解決 FilterDispatcher 棄用警告:遷移至 StrutsPrepareAndExecuteFilter

     編輯:Java 綜合教學

Struts 2.3.31+ 解決 FilterDispatcher 棄用警告:遷移至 StrutsPrepareAndExecuteFilter

問題現象

web.xml 使用舊配置:

<filter>
  <filter-name>struts2</filter-name>
  <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>

啟動報警告:

***********************************************************************
* WARNING!!!                                                          *
* >>> FilterDispatcher <<< is deprecated! Please use the new filters! *
* This can be a source of unpredictable problems!                     *
* https://struts.apache.org/2.x/docs/webxml.html                       *
***********************************************************************

原因

FilterDispatcher 自 Struts 2.1.3 起標記 @Deprecated,官方建議替換為 StrutsPrepareAndExecuteFilter(或組合 StrutsPrepareFilter + StrutsExecuteFilter 需配合 ActionContextCleanUp)。

解決方案

修改 web.xml:

<filter>
  <filter-name>struts2</filter-name>
  <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>

重啟項目,警告消失,功能正常。

補充說明

  • ng.filter 包下為新一代過濾器實現
  • 若需額外清理 ActionContext,可配置兩個 Filter:StrutsPrepareFilter (pre) + StrutsExecuteFilter (post)
  • 升級 Struts 版本時同步更新 web.xml 是必做項
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved