架构整合要点。

整合spring2 + struts1.2 + hibernate3.2

程序要使用spring2,需要spring插件jar包和spring的类库外。
1.web.xml配置spring的监听。



org.springframework.web.context.ContextLoaderListener






通过contextConfigLocation上下文参数指定spring配置文件



javax.servlet.jsp.jstl.fmt.localizationContext

/i18nMessage/MessageResources




2。spring整合struts1
spring 对struts的支持有3种模式,分别是代理模式,控制器继承和插件模式,这里使用控制器模式。即采用spirng的controller处理器,实际上spring的处理器继承了struts.修改的struts如下
struts-config.xml配置
           




struts-action.xml和spring-action.xml配置


attribute="departmentForm" scope="request" parameter="dispatch">

path="/department/departmentForm.jsp" />












class="com.ving.xzfw.action.DepartmentAction" scope="request">


ref="dictionaryTypeBOService" />





bean的name属性一定要和action的path的名称相同


就这样struts的action便可以使用spring的IOC特性了
3spring集成hibernate
  












com/tlb/db/domain/User.hbm.xml
com/tlb/db/domain/Song.hbm.xml




org.hibernate.dialect.MySQLDialect
true












配置好后,我们就可在DAO中调用sessionFactory进行各种操作。不再需要自己写一大堆数据库的共通类。HibernateDaoSupport 提供了丰富的方法,足够我们使用。而且由于spring对异常的封装机制,我们的程序代码,再也不需要很多的try catch 了。

public class UserDao extends HibernateDaoSupport implements IUserDao {

public void insUser(User user) throws DataAccessException {
// TODO Auto-generated method stub
this.getHibernateTemplate().save(user);
}

}

你可能感兴趣的:(OPEN,Spring,Struts,Java,Hibernate,XML)