星空网 > 软件开发 > Java

Spring与Struts2集成开发

Struts2和Spring都是不错的开源框架,Spring与Struts2集成开发,把二者结合在一起使用,开发效果更佳,效率杠杠的。下面介绍一下如何将Spring与Struts2集成在一起开发。分七步战略:
1、添加Struts2 支持jar包 ;注意:加上一个Struts-spring-plugin(集成)插件包2、添加spring 支持jar包3、编写struts.
<!DOCTYPE struts PUBLIC  "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"  "http://struts.apache.org/dtds/struts-2.3.dtd">  <struts>    <package name="default" namespace="/" extends="struts-default">      <!-- 配置用户ACTION         Action由Spring维护        class就是spring中Action Bean的ID      -->      <action name="useraction*" class="useraction" method="{1}">        <result name="success" type="redirect">success.jsp</result>        <result name="login" type="redirect">index.jsp</result>      </action>          </package>  </struts>

 

4、在web.
<??><web-app version="2.5"   ="http://java.sun.com/   ="http://www.w3.org/2001/   xsi:schemaLocation="http://java.sun.com/>  <!-- 配置struts2核心过滤器 -->  <filter>    <filter-name>Struts2</filter-name>    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>  </filter>  <filter-mapping>    <filter-name>Struts2</filter-name>    <url-pattern>/*</url-pattern>  </filter-mapping>    <!-- 指定spring配置文件所在位置 -->  <context-param>    <param-name>contextConfigLocation</param-name>    <param-value>classpath:applicationContext.</param-value>  </context-param>  <!-- 配置sprig** -->  <listener>    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  </listener>    <welcome-file-list>   <welcome-file>index.jsp</welcome-file>  </welcome-file-list></web-app>

 

	5、编写spring配置文件applicationContext.
<??><beans ="http://www.springframework.org/schema/beans"    ="http://www.w3.org/2001/    xsi:schemaLocation="http://www.springframework.org/schema/beans      http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">    <!-- 配置持久化层 new userdao()-->  <bean id="userdao" class="DAO.impl.UserDaoimpl" scope="prototype"></bean>    <!-- 创建业务层 new userbiz() -->   <bean id="userbiz" class="BIZ.impl.UserBizimpl" scope="prototype">     <!-- 注入持久化层 DAO       IUuserDao userdao = new userdao()     -->     <property name="userdao" ref="userdao"></property>   </bean>      <bean id="useraction" class="Action.UserAction" scope="prototype">     <!-- 注入业务层BIZ        IUserBiz userbiz = new UserBiz()     -->     <property name="userbiz" ref="userbiz"></property>   </bean></beans>

 

6、在web.
    <!-- 指定spring配置文件所在位置 -->  <context-param>    <param-name>contextConfigLocation</param-name>    <param-value>classpath:applicationContext.</param-value>  </context-param>  <!-- 配置sprig** -->  <listener>    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  </listener>

 

7、编写三层结构;通过spring依次注入各依赖对象	BIZ 中注入 DAO层	Action 层中注入 BIZ层



原标题:Spring与Struts2集成开发

关键词:Spring

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

一款优秀的外贸管理软件,到底能给企业带来多少价值?:https://www.kjdsnews.com/a/1452227.html
跨境一周资讯 | TikTok Shop跨境电商全托管模式上线:https://www.kjdsnews.com/a/1452228.html
谷歌关键词广告如何写好广告词:https://www.kjdsnews.com/a/1452229.html
化学品安全技术说明书MSDS报告编制中的常见错误:https://www.kjdsnews.com/a/1452230.html
别只盯着东南亚,更有潜力的市场是“它”:https://www.kjdsnews.com/a/1452231.html
亚马逊不同类型账号介绍:https://www.kjdsnews.com/a/1452232.html
怪物在游轮上复活的电影 怪物在游轮上复活的电影叫什么:https://www.vstour.cn/a/411230.html
在线旅游如何选择更优惠的旅游产品?:https://www.vstour.cn/a/411231.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流