当前位置:编程学习 > JS >>

struts2 spring整配置

[html] 
(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> 
(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>

 作者:Tender001
 

补充:Web开发 , Jsp ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,