posts - 119, comments - 62, trackbacks - 0, articles - 0

          struts2 spring配置

          Posted on 2008-08-22 17:41 Kevin Meng 閱讀(2423) 評論(0)  編輯  收藏

          (1)在eclipse中配置好struts2

          (2)把struts2-spring-plugin-2.0.11.2.jar包復制到WEB-INF\lib目錄
          (3)在web.xml中配置spring
          <listener>
              <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
          </listener>
          記住,如果您之前用過spring,請把spring配置去掉。
           <servlet>
            <servlet-name>context</servlet-name>
            <servlet-class>
             org.springframework.web.context.ContextLoaderServlet
            </servlet-class>
            <load-on-startup>1</load-on-startup>
           </servlet>
          (4)修改applicationContext.xml
          <beans default-autowire="byName" xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
          (5)在struts.xml加入
          <constant name="struts.objectFactory" value="spring" />
          (6)在spring的配置文件applicationContext.xml中定義action
          <bean id="SearchBusLineAction"
            class="com.bus.struts2.action.SearchBusLineAction" abstract="false"
            lazy-init="default" autowire="default" dependency-check="default">
            <property name="busService">
             <ref bean="BusServiceImpl" />
            </property>
           </bean> 
          (7)在struts.xml中定義action
          <!-- 注意這里class="SearchBusLineAction"而不是com.bus.struts2.action.SearchBusLineAction是因為這個已經在spring的applicationContext.xml中定義 -->
            <action name="searchBusLine" class="SearchBusLineAction">
             <result name="success" type="freemarker">/index.jsp</result>
            </action>

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


          網站導航:
           
          主站蜘蛛池模板: 左贡县| 仪征市| 卢龙县| 崇文区| 宁远县| 揭阳市| 丹棱县| 循化| 股票| 额济纳旗| 灌云县| 塔城市| 秭归县| 华亭县| 泾阳县| 玉田县| 临江市| 梁平县| 米林县| 昭苏县| 大名县| 山阴县| 株洲市| 喜德县| 瑞丽市| 巫山县| 大方县| 鹤庆县| 合川市| 广饶县| 逊克县| 育儿| 东丰县| 阿克苏市| 高台县| 永川市| 法库县| 雷波县| 四子王旗| 晴隆县| 保定市|