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

          struts2 spring配置

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

          (1)在eclipse中配置好struts2

          (2)把struts2-spring-plugin-2.0.11.2.jar包復(fù)制到WEB-INF\lib目錄
          (3)在web.xml中配置spring
          <listener>
              <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
          </listener>
          記住,如果您之前用過spring,請(qǐng)把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是因?yàn)檫@個(gè)已經(jīng)在spring的applicationContext.xml中定義 -->
            <action name="searchBusLine" class="SearchBusLineAction">
             <result name="success" type="freemarker">/index.jsp</result>
            </action>

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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 龙泉市| 京山县| 自治县| 湛江市| 中方县| 阿合奇县| 沐川县| 石嘴山市| 饶河县| 莒南县| 郎溪县| 齐河县| 星子县| 阜阳市| 宾阳县| 九台市| 屏东县| 姚安县| 屏山县| 崇明县| 巴林左旗| 大余县| 丹寨县| 溧水县| 资阳市| 托里县| 宁远县| 韩城市| 如东县| 商丘市| 民和| 敦化市| 尉犁县| 建平县| 永泰县| 浏阳市| 桂平市| 大邑县| 大冶市| 砀山县| 承德县|