S2SH三者整合方案

注:两种方案非手动式的。
S2SH三者整合方案一(MyEclipse Blue Edition 8.6):
第一步:新建一个Web项目,然后为这个项目添加Spring能力。
第二步:添加hibernate能力,这个过程中不需要hibernate的配置文件hibernate.hbm.xml;重点是添加相关的架包;
第三步:将hibernate的配置信息配置到Spring的配置文件中,由Spring来管理hibernate;重点在于dataSource和sessionFactory的配置;
第四步:添加struts2能力,并把struts.xml文件放在类路径下;
第五步:把struts2交给Spring管理,有二种配置方式:第一种,新建一个struts. Properties,写入struts.objectFactory=spring;第二种方式:在struts.xml中加入<constant name="struts.objectFactory" value="spring" />  ;即就是把action的对象交给Spring创建。

第六步:在web.xml中配置spring的下上文和监听器。即:
<context-param> 
         <param-name>contextConfigLocation</param-name> 
         <param-value>路径+xxxxxxxx.xml/param-value> 
     </context-param> 
      
    <listener> 
          <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener> 
同时还要添加struts2的过滤器和过滤的访问资源;
第七步:在spring的配置文件中配置事务,把需要管理的业务处理的实现类添加到配置文件中;
第八步:在spring配置文件中配置action时,注意把action的定义为原型,因为spring默认实例化bean时为单例模式;
第九步:注意在struts.xml中的配置action时,对应的class是spring配置文件中的对应类的Bean的名字;

第十步:部署工程,进行测试,tomcat能正常启动,可以大体上认为三者整合基本成功。

S2SH三者整合方案二(MyEclipse Blue Edition 8.6):
第一步:新建一个Web项目,然后为这个项目添加Spring能力。
第二步:添加hibernate能力,这个过程中不需要hibernate的配置文件hibernate.hbm.xml;重点是添加相关的架包;
第三步:将hibernate的配置信息配置到Spring的配置文件中,由Spring来管理hibernate;重点在于dataSource和sessionFactory的配置;
第四步:添加struts2能力,并把struts.xml文件放在类路径下;
第五步:将action要访问的业务处理类的接口 利用AOP技术进行代理,在spring配置文件进行配置。这时就不需要在spring中配置struts2。
第六步:在web.xml中配置spring的下上文和监听器。即:
<context-param> 
         <param-name>contextConfigLocation</param-name> 
         <param-value>路径+xxxxxxxx.xml/param-value> 
     </context-param> 
      
    <listener> 
          <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener> 
同时还要添加struts2的过滤器和过滤的访问资源;
第七步:部署工程,进行测试,tomcat能正常启动,可以大体上认为三者整合基本成功。


你可能感兴趣的:(spring,Hibernate,MyEclipse,struts,配置管理)