3
如何從struts2.xml在struts.xml中注入動作的實現類?如何在struts.xml中重新映射Action實現類?
設在struts.xml如下所示:
<struts>
<action name="EnginesList" class="example.EnginesListAction">
<result name="*">viewengines.jsp</result>
</action>
</struts>
然後我想實現:在當struts2.xml存在(或不爲空),然後在struts2.xml類的映射覆蓋那些struts.xml中。所以如果我有以下定義,那麼在運行時EnginesList被映射到example.EnginesListAction2而不是example.EnginesListAction。
// struts.xml:
<struts>
<action name="EnginesList" class="example.EnginesListAction">
<result name="*">viewengines.jsp</result>
</action>
<include file="struts2.xml" />
</struts>
// struts2.xml
<struts>
<action name="EnginesList" class="example.EnginesListAction2">
<result name="*">viewengines.jsp</result>
</action>
</struts>
由於名稱衝突,這似乎不起作用。那麼實現我最終目標的最佳方式是什麼?
背景加入:
- 隊-A開發和維護的struts.xml。我的團隊(團隊B)使用團隊A的代碼庫並將其部署到單獨的數據中心。
- Team-B需要將一些動作映射到不同的類。但是我們不能在struts.xml中直接修改它,因爲它會改變Team-A服務的行爲。
- 所以我想要的是有一個單獨的文件(struts2.xml),它的類映射可以覆蓋struts.xml中的文件。行動包名稱沒有變化。 JSP代碼沒有變化。這個struts2.xml將只被部署在B隊的數據中心。
你的最終目標*是什麼?你爲什麼需要這個? – 2014-09-03 08:39:17
@AleksandrM struts.xml由團隊A維護,我們的團隊(團隊B)不允許修改struts.xml中的類映射,所以我們必須從單獨的文件中注入類映射。如果這個注入有效,那麼team-A只在加載了struts.xml的情況下啓動它們的服務器,而team-B在加載struts.xml和struts2.xml的同時啓動它們的服務器。 – zzhang 2014-09-03 14:28:07
@zzhang編輯一個問題,您可以在編輯:**標記下添加詳細信息,而不是從中刪除重要內容,試圖以這種方式修改問題。 – 2014-09-03 16:03:56