struts1.x+spring+hibernate集成

struts1.x+spring+hibernate集成(Action交给spring来创建,这时候要注意代理,实现了接口的类才能使用JDK动态代理,没有实现接口的类则只能使用CGLIB)

 

 * 将所有的jar包拷贝到WEB-INF/lib下,如果jar包有重复的则删除一些,去版本新的

 * 将spring,struts,hibernate的配置文件拷贝过来,spring和hibernate的放在src目录下,struts的放在WEB-INF

   在str下:

             applicationContext-action.xml

             applicationContext-bean.xml

             applicationContext-commons.xml (放的是申明式事务)

             hibernate.cfs.xml

(在hibernate中加入:<property name="hibernate.hbm2ddl.auto">update</property>)

加入这个后不用我们手动的导出表,当创建SessionFactory的时候就会自动的导出

             log4j.properties

             MessageResources.properties

在WEB-INF下:struts.config.xml    web.xml

                       在web.xml文件中要加入<context-param>和<listener>标签

 

 

1,解决字符集问题(采用Spring提供的filter)(将以下内容放到web.xml文件中)

 

   <filter>
     <filter-name>Spring character encoding filter</filter-name>
     <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
     
     <init-param>
      <param-name>encoding</param-name>
      <param-value>GBK</param-value>
     </init-param>
 </filter>

  <filter-mapping>
    <filter-name>Spring character encoding filter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

 

2,为了避免hibernate的懒加载异常而创建的解决方案

      仍然是采用spring提供的

      下面的是一个过滤器,能够让Session在请求解释完成后关闭(所以才能避免懒加载异常),将下面的代码copy到web.xml中

 

   <filter>
    <filter-name>hibernateFilter</filter-name>
    <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
  </filter>
 <filter-mapping>
    <filter-name>hibernateFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

 

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值