SSH2整合

1.SSH2的整合:
a.加入Struts2的jar包
b.加入struts2和spring关联的jar包(struts2-spring-plugin-2.0.14.jar)
c.在spring_action.xml中注入action时:
  <bean id="actionName" class="action的完全先定名path">
   <property name="iservice" ref="iservice"/>    -----初始化关联对象
   <property name="user" ref="user"/>
   </bean>
  
d.在struts2中的struts.xml中配置action
   I.配置常量:将struts委托给spring容器========>可要可不要(默认)
    <constant name="struts.objectFactory" value="spring"></constant>
    <action name="名称" class="actionName"></action>
   
    注意:1.其他的步骤和整合SSH的过程一样。
          2.在SSH2中<description>配置过滤器实现懒加载</description>时,该过滤器必须放在web.xml配置文件中的最前边。
         
         
2.整合中IDAO接口的方法时,我们可以加上"日志信息,提示业务操作的失败和成功的信息"。
  a.实现类的方法.------------->必须RuntimeException异常。(Log在org.apache.commons.logging.Log下)
  例如:public static final Log log=LogFactory.getLog(接口实现类.class);
        public Object get(Class cls, Serializable id) {
       try {
this.log.debug("find Object,id:"+id);--------->设置提示信息
return this.getHibernateTemplate().get(cls, id);
} catch (RuntimeException e) {
   this.log.error("find failed",e);-------------->保存错误信息
    throw e;                         -------------->抛出该异常
}
}

   注意: Filter配置顺序的原因:
SSH2正确顺序:
OpenSessionInViewFilter
ActionContextCleanUp
FilterDispatcher
以及其他的Filter

猜你喜欢

转载自hongzhguan.iteye.com/blog/1044406