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

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

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

    176142998

      BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
      116 Posts :: 0 Stories :: 45 Comments :: 0 Trackbacks
     在Struts2中整合Spring的IoC支持是一件十分簡單的事情。讓我們一步一步來實現(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
        struts.objectFactory = spring
        或者是在XML文件中進(jìn)行常量配置

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

        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>
        當(dāng)然你也可以擁有更多的Spring配置文件。在web.xml中進(jìn)行下列設(shè)置,從而使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>
        默認(rèn)情況下,Spring從上面顯示的applicationContext.xml文件中尋找為hello所做的配置

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

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


        是否使用類緩存。你可以通過設(shè)置修改struts.properties中下列屬性的值來改變是否使用Spring自身的類緩存機(jī)制??梢栽O(shè)定的值為true或false,默認(rèn)為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 飛飛 閱讀(307) 評論(0)  編輯  收藏

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


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 亚洲性日韩精品一区二区三区| 亚洲色在线无码国产精品不卡| 精品免费国产一区二区三区| 日本高清高色视频免费| 亚洲丁香婷婷综合久久| 亚洲国产精品人久久电影| 亚洲线精品一区二区三区影音先锋 | 国产亚洲成在线播放va| 亚洲成a人片毛片在线| 国产亚洲精品a在线无码| 国产a不卡片精品免费观看| 美女网站免费福利视频| 香蕉成人免费看片视频app下载| 九九免费观看全部免费视频| 亚洲午夜福利在线视频| 亚洲AV无码一区二区三区牛牛| 久久亚洲精品AB无码播放| 亚洲永久无码3D动漫一区| 九月婷婷亚洲综合在线| 香蕉视频在线观看免费国产婷婷| 亚洲人成在线免费观看| 最近2019免费中文字幕6| 无码专区AAAAAA免费视频| 国产成人AV片无码免费| 国产永久免费高清在线| 中文成人久久久久影院免费观看| 无忧传媒视频免费观看入口| 国产精品无码亚洲一区二区三区| 亚洲乱色伦图片区小说| 亚洲成在人线在线播放无码| 一本天堂ⅴ无码亚洲道久久| 一本色道久久88—综合亚洲精品| 亚洲制服丝袜一区二区三区| 亚洲人成影院午夜网站| 亚洲性无码AV中文字幕| 亚洲欧美日韩中文无线码 | 国产在线a不卡免费视频| 国产成人精品男人免费| 免费观看亚洲人成网站| 久久久久久亚洲精品不卡| 亚洲一级片免费看|