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

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

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

    176142998

      BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
      116 Posts :: 0 Stories :: 45 Comments :: 0 Trackbacks
     在Struts2中整合Spring的IoC支持是一件十分簡單的事情。讓我們一步一步來實現:
        1)復制struts2-spring-plugin-x-x-x.jar和相應的spring.jar到/WEB-INF/lib目錄下。
        2)在struts.properties中設置struts.objectFactory屬性值


        struts.properties
        struts.objectFactory = spring
        或者是在XML文件中進行常量配置

        struts.xml
        <struts>
            <constant name="struts.objectFactory" value="spring" />
        </struts>
        3)配置Spring監聽器

        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>
        當然你也可以擁有更多的Spring配置文件。在web.xml中進行下列設置,從而使Spring的ApplicationContext通過匹配所給定模式的文件來初始化對象

        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)修改你的Struts配置文件

        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">
                    <result>hello.jsp</result>
                </action>
        </struts>
        默認情況下,Spring從上面顯示的applicationContext.xml文件中尋找為hello所做的配置

    5)好了,現在你的Struts2和Spring就能正常的一起工作了。有幾個配置技術點需要詳細說明下:
        裝配模式。你可以通過設置修改struts.properties中下列屬性的值來改變裝配模式。

        name 按照你的action的屬性的名字和Spring里的bean的名字匹配,如果匹配就自動裝配。這是缺省的
        type 按照你的action的屬性的類型,在Spring注冊的bean中查找,如果相同就自動裝配。這需要你在Spring中僅注冊了一個此類型的bean
        auto Spring會試圖自動監測來找到最好的方法自動裝配你的action
        constructor Spring會自動裝配bean的構造函數的參數


        是否使用類緩存。你可以通過設置修改struts.properties中下列屬性的值來改變是否使用Spring自身的類緩存機制。可以設定的值為true或false,默認為true。

        struts.properties
        struts.objectFactory.spring.useClassCache = false


    http://dev.rdxx.com/Java/Struts/2008/5/2313512756889_2.shtml

    posted on 2008-06-12 15:55 飛飛 閱讀(306) 評論(0)  編輯  收藏

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 免费人成大片在线观看播放| 麻豆亚洲av熟女国产一区二| 亚洲欧美黑人猛交群| 国产一卡2卡3卡4卡2021免费观看| 激情内射亚洲一区二区三区| 99精品视频在线免费观看 | 亚洲啪啪免费视频| 4444亚洲国产成人精品| 100部毛片免费全部播放完整| 精品亚洲成a人片在线观看| 3d动漫精品啪啪一区二区免费 | 成人毛片免费观看视频| 亚洲熟女精品中文字幕| 日本二区免费一片黄2019| 黄色a级免费网站| 黑人大战亚洲人精品一区| 最新国产乱人伦偷精品免费网站 | 久久久久久a亚洲欧洲aⅴ| 国产精品99久久免费观看| 亚洲日本香蕉视频观看视频| 免费看韩国黄a片在线观看| 亚洲a∨国产av综合av下载| 亚洲AⅤ视频一区二区三区| 成人性生交大片免费看中文| 亚洲综合综合在线| 国产美女被遭强高潮免费网站| 二级毛片免费观看全程| 亚洲av无码不卡一区二区三区| 亚洲毛片免费观看| 处破女第一次亚洲18分钟| 伊人久久大香线蕉亚洲五月天 | 免费视频成人国产精品网站| 国产成人综合亚洲亚洲国产第一页| 久草福利资源网站免费| 亚洲精品第一国产综合野| 亚洲高清无码在线观看| 久久午夜伦鲁片免费无码| 精品特级一级毛片免费观看| 亚洲AV无一区二区三区久久| 成熟女人牲交片免费观看视频| 国产免费久久精品99久久|