Spring_hibernate_struts整合(集成配置)

4 篇文章 0 订阅
4 篇文章 0 订阅

Spring_hibernate_struts整合:
1、通过MyEclipse添加hibernate支持;
2、通过MyEclipse添加Spring支持;
3、建立工程所需的包结构;
4、通过hibernate的逆向工程将关系模型生成相应的对象模型组件(实体类及其映射文件);
5、开发DAO层及业务层;
6、在spring配置文件对DAO对象及业务对象进行配置:
 1)将sessionFactory注入到DAO对象中;
 2)将DAO对象注入到业务对象中;
7、测试查询方法; 
8、将hibernate配置与spring配置整合到一起(注意:需要将数据库连接池所需的jar包导入到工程中)(spring-framework-2.0.1/lib/jackarta-commons/commons-dbcp.jar+commons-poll.jar);
标签头文件在:spring-framework-2.0.1/samples/jpetstore/war/web-inf/applicationContext.xml(完整的头文件)
9、重新测试;
10、为应用添加事务的支持(声明式事务):
 1)声明一个hibernate3的事务管理器,供代理类自动管理事务,例如:
 <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  <property name="sessionFactory" ref="sessionFactory"/>
 </bean> 
 2)定义事务通知,需要指定一个事务管理器,例如:
 <tx:advice id="txAdvice" transaction-manager="transactionManager">
  <!-- 定义在各种方法上事务的传播特性(事务规则) -->
  <tx:attributes>
   <tx:method name="add*" propagation="REQUIRED"/>
   <tx:method name="delete" propagation="REQUIRED"/>
   <tx:method name="update" propagation="REQUIRED"/>
   <tx:method name="*" propagation="SUPPORTS" read-only="true"/>
  </tx:attributes>
 </tx:advice>
 3)定义切面,即在哪些方法应用事务规则,例如:
 <aop:config>
  <!-- 定义切入点 -->
  <aop:pointcut id="bizMethods" expression="execution(* edu.accp.biz.impl.*.*(..))"/>
  <!-- 将切入点与通知结合 -->
  <aop:advisor advice-ref="txAdvice" pointcut-ref="bizMethods"/>
 </aop:config>
11、通过MyEclipse添加Struts支持;
12、开发出相应的JSP、ActionForm和Action;
13、将Struts与Spring集成:
 1)运用Struts的插件方法,添加struts-congif.xml的<plug-in>节点:
 <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
    <set-property property="contextConfigLocation" value="classpath:application*.xml"/>
   </plug-in>
   2)将Struts中的Action的type属性统一修改为:org.springframework.web.struts.DelegatingActionProxy;
   3)在spring配置文件声明Action对象,并将业务对象注入到Action对象中;
14、删除冲突的Jar包:spring2.0 AOP Libraries下的 asm-2.2.3.jar

 
 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值