struts.properties
struts.objectFactory = spring
鎴栬呮槸鍦╔ML鏂囦歡涓繘琛屽父閲忛厤緗?
struts.xml
<struts>
<constant name="struts.objectFactory" value="spring" />
</struts>
3錛夐厤緗甋pring鐩戝惉鍣?
web.xml
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
閫氳繃Spring閰嶇疆鏉ユ敞鍐屽璞?
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC
"-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans default-autowire="autodetect">
<bean id="hello" class="hpfyeah.struts2.spring.HelloWorldAction"/>
</beans>
褰撶劧浣犱篃鍙互鎷ユ湁鏇村鐨凷pring閰嶇疆鏂囦歡銆傚湪web.xml涓繘琛屼笅鍒楄緗紝浠庤屼嬌Spring鐨凙pplicationContext閫氳繃鍖歸厤鎵緇欏畾妯″紡鐨勬枃浠舵潵鍒濆鍖栧璞?
web.xml
<!-- 鐢ㄦ潵瀹氫綅Spring XML鏂囦歡鐨勪笂涓嬫枃閰嶇疆 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext-*.xml,classpath*:applicationContext-*.xml
</param-value>
</context-param>
4錛変慨鏀逛綘鐨凷truts閰嶇疆鏂囦歡
struts.xml
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<include file="struts-default.xml"/>
<package name="default" extends="struts-default">
<action name="pureStruts" class="hpfyeah.struts2.spring.HelloWorldAction">
<result>hello.jsp</result>
</action>
<action name="springStruts" class="hello">
5錛夊ソ浜嗭紝鐜板湪浣犵殑Struts2鍜孲pring灝辮兘姝e父鐨勪竴璧峰伐浣滀簡銆傛湁鍑犱釜閰嶇疆鎶鏈偣闇瑕佽緇嗚鏄庝笅錛?br /> 瑁呴厤妯″紡銆備綘鍙互閫氳繃璁劇疆淇敼struts.properties涓笅鍒楀睘鎬х殑鍊兼潵鏀瑰彉瑁呴厤妯″紡銆?
name 鎸夌収浣犵殑action鐨勫睘鎬х殑鍚嶅瓧鍜孲pring閲岀殑bean鐨勫悕瀛楀尮閰嶏紝濡傛灉鍖歸厤灝辮嚜鍔ㄨ閰嶃傝繖鏄己鐪佺殑
type 鎸夌収浣犵殑action鐨勫睘鎬х殑綾誨瀷錛屽湪Spring娉ㄥ唽鐨刡ean涓煡鎵撅紝濡傛灉鐩稿悓灝辮嚜鍔ㄨ閰嶃傝繖闇瑕佷綘鍦⊿pring涓粎娉ㄥ唽浜嗕竴涓綾誨瀷鐨刡ean
auto Spring浼氳瘯鍥捐嚜鍔ㄧ洃嫻嬫潵鎵懼埌鏈濂界殑鏂規硶鑷姩瑁呴厤浣犵殑action
constructor Spring浼氳嚜鍔ㄨ閰峛ean鐨勬瀯閫犲嚱鏁扮殑鍙傛暟
鏄惁浣跨敤綾葷紦瀛樸備綘鍙互閫氳繃璁劇疆淇敼struts.properties涓笅鍒楀睘鎬х殑鍊兼潵鏀瑰彉鏄惁浣跨敤Spring鑷韓鐨勭被緙撳瓨鏈哄埗銆傚彲浠ヨ瀹氱殑鍊間負true鎴杅alse錛岄粯璁や負true銆?