<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    本站不再更新,歡迎光臨 java開發(fā)技術(shù)網(wǎng)
    隨筆-230  評(píng)論-230  文章-8  trackbacks-0

    整合 Spring 和 Strust2 一起工作

    關(guān)鍵字:   struts2 spring    
    在Struts2中整合Spring的IoC支持是一件十分簡(jiǎn)單的事情。讓我們一步一步來(lái)實(shí)現(xiàn):
    1)復(fù)制struts2-spring-plugin-x-x-x.jar和相應(yīng)的spring.jar到/WEB-INF/lib目錄下。
    2)在struts.properties中設(shè)置struts.objectFactory屬性值

    struts.properties
    1. struts.objectFactory = spring  

    或者是在XML文件中進(jìn)行常量配置

    struts.xml
    1. <struts>  
    2.     <constant name="struts.objectFactory" value="spring" />  
    3. </struts>  

    3)配置Spring監(jiān)聽(tīng)器

    web.xml
    1. <listener>  
    2.     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
    3. </listener>  

    通過(guò)Spring配置來(lái)注冊(cè)對(duì)象

    applicationContext.xml
    1. <?xml version="1.0" encoding="UTF-8"?>  
    2. <!DOCTYPE beans PUBLIC    
    3.     "-//SPRING//DTD BEAN//EN"   
    4.     "http://www.springframework.org/dtd/spring-beans.dtd">  
    5. <beans default-autowire="autodetect">  
    6.     <bean id="hello" class="hpfyeah.struts2.spring.HelloWorldAction"/>  
    7. </beans>  

    當(dāng)然你也可以擁有更多的Spring配置文件。在web.xml中進(jìn)行下列設(shè)置,從而使Spring的ApplicationContext通過(guò)匹配所給定模式的文件來(lái)初始化對(duì)象

    web.xml
    1. <!-- 用來(lái)定位Spring XML文件的上下文配置 -->  
    2. <context-param>  
    3.     <param-name>contextConfigLocation</param-name>  
    4.     <param-value>
    5.         /WEB-INF/applicationContext-*.xml,classpath*:applicationContext-*.xml
    6.     </param-value>  
    7. </context-param>  

    4)修改你的Struts配置文件

    struts.xml
    1. <!DOCTYPE struts PUBLIC      
    2.     "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"      
    3.     "http://struts.apache.org/dtds/struts-2.0.dtd">     
    4. <struts>     
    5.     <include file="struts-default.xml"/>     
    6.     <package name="default" extends="struts-default">     
    7.         <action name="pureStruts" class="hpfyeah.struts2.spring.HelloWorldAction">
    8.             <result>hello.jsp</result>     
    9.         </action>  
    10.         <action name="springStruts" class="hello">      
    11.             <result>hello.jsp</result>     
    12.         </action>     
    13. </struts>  

    默認(rèn)情況下,Spring從上面顯示的applicationContext.xml文件中尋找為hello所做的配置

    5)好了,現(xiàn)在你的Struts2和Spring就能正常的一起工作了。有幾個(gè)配置技術(shù)點(diǎn)需要詳細(xì)說(shuō)明下:
    裝配模式。你可以通過(guò)設(shè)置修改struts.properties中下列屬性的值來(lái)改變裝配模式。

    name 按照你的action的屬性的名字和Spring里的bean的名字匹配,如果匹配就自動(dòng)裝配。這是缺省的
    type 按照你的action的屬性的類型,在Spring注冊(cè)的bean中查找,如果相同就自動(dòng)裝配。這需要你在Spring中僅注冊(cè)了一個(gè)此類型的bean
    auto Spring會(huì)試圖自動(dòng)監(jiān)測(cè)來(lái)找到最好的方法自動(dòng)裝配你的action
    constructor Spring會(huì)自動(dòng)裝配bean的構(gòu)造函數(shù)的參數(shù)

    是否使用類緩存。你可以通過(guò)設(shè)置修改struts.properties中下列屬性的值來(lái)改變是否使用Spring自身的類緩存機(jī)制。可以設(shè)定的值為true或false,默認(rèn)為true。

    struts.properties
    1. struts.objectFactory.spring.useClassCache = false 
    按照以上步驟做了,但出錯(cuò)、異常信息如下
    Messages:
    1. springhello
    2. Action class [springhello] not found
    File: com/caucho/loader/DynamicClassLoader.java
    Line number: 1,124
    posted on 2007-10-24 17:54 有貓相伴的日子 閱讀(2646) 評(píng)論(2)  編輯  收藏 所屬分類: spring

    評(píng)論:
    # re: struts2和spring2整合(轉(zhuǎn)) 2007-11-12 23:04 | 有貓相伴的日子
    找到原因了,修改web.xml文件,把
    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
    /WEB-INF/applicationContext.xml,/WEB-INF/action-servlet.xml
    </param-value>
    </context-param>

    放最前面  回復(fù)  更多評(píng)論
      
    # re: struts2和spring2整合(轉(zhuǎn)) 2008-07-16 14:36 | vist
    @有貓相伴的日子
    這樣能行,8可能吧~??  回復(fù)  更多評(píng)論
      
    本站不再更新,歡迎光臨 java開發(fā)技術(shù)網(wǎng)
    主站蜘蛛池模板: 亚洲日本在线免费观看| 亚洲AV日韩综合一区尤物| 国产大陆亚洲精品国产| 国产大片免费网站不卡美女| 久久精品国产精品亚洲艾草网 | 七次郎成人免费线路视频 | 精品国产污污免费网站入口在线| 免费特级黄毛片在线成人观看| 亚洲综合校园春色| 成人免费一区二区三区在线观看| 亚洲欧洲另类春色校园小说| 国产成人综合亚洲AV第一页 | 亚洲一区欧洲一区| 好男人视频社区精品免费| 亚洲日本天堂在线| 三年片在线观看免费西瓜视频 | 亚洲爽爽一区二区三区| 国产成人无码免费看片软件| 亚洲无码在线播放| 最近免费中文字幕大全免费 | 亚洲一级黄色视频| 国产无遮挡无码视频免费软件| 亚洲av无码一区二区三区不卡 | 大学生一级特黄的免费大片视频| 日韩欧美亚洲中文乱码| ZZIJZZIJ亚洲日本少妇JIZJIZ| 国产午夜精品理论片免费观看 | 四虎影视永久免费观看| 高清永久免费观看| 91亚洲精品视频| 日本一区免费电影| 亚洲黄色免费网址| 卡一卡二卡三在线入口免费| 日韩精品无码免费视频| 亚洲国语精品自产拍在线观看| 波多野结衣免费在线观看| 边摸边吃奶边做爽免费视频99| 亚洲日韩中文无码久久| 免费无码AV片在线观看软件| 中美日韩在线网免费毛片视频| 亚洲精品在线免费观看视频|