附件:整合过程word文档。s2sh无注解整合.zip与参考资料http://115.com/lb/5lbfh77s#Spring+Struts2+Hibernate整合整合过程1、 配置srping启动监听器,使spring容器在web应用启动的时候启动,在web.xml中(参考文档:H:\struts-2.2.1.1\docs\WW\spring-plugin.html):
org.springframework.web.context.ContextLoaderListener
contextConfigLocation
classpath:bean.xml
2、 由Spring来管理Actiona、注解方式@Component(value="testAction")@Scope(value="prototype")public class TestAction extends ActionSupport {public String test(){System.out.println("action........");return this.SUCCESS;}}b、也可以通过xml方式,把Action当作普通的bean配置spring文件的头部引用:在spring-framework-2.5.6/docs/reference/html-single 输入XML查找然后复制
(1)注入service到action中(注意:scope="prototype"表示不为单例模式,即每次执行增加或者修改操作都新创建一个action;property中的name值是class类中的变量)
(2)读src下的属性文件的bean配置
classpath:myserver.properties
3、 由Spring来管理Hibernate(1)配置数据源,连接数据库:value中的值在myserver.properties文件中定义,注意变量名要一致
${jdbc.driverClass}
${jdbc.url}
${jdbc.user}
${jdbc.password}
(2)配置SessionFactory
User.hbm.xml
${hibernate.dialect}
${hibernate.show_sql}
(3)配置事务管理模板化hibernate持久层
定义Dao父类模板,要为抽象的,把模板化的hibernate持久层注入到dao中
把dao注入到service层
PROPAGATION_REQUIRED
(4)Properties中sqlserver与mysql的连接方式#jdbc.driverClass="com.microsoft.jdbc.sqlserver.SQLServerDriver"jdbc.driverClass=com.mysql.jdbc.Driver#jdbc.url="jdbc:sqlserver://127.0.0.1:3306;DatabaseName=test"jdbc.url=jdbc:mysql://localhost:3306/testjdbc.user=rootjdbc.password=root #hibernate.dialect="org.hibernate.dialect.SQLServerDialect"hibernate.dialect=org.hibernate.dialect.MySQL5Dialecthibernate.show_sql=true 4、 Hibernate的*.hbm.xml的配置
5、 Struts2的配置(1)写struts2.xml文件:复制:struts-2.2.1.1\apps\struts2-blank\web-inf\classes\struts.xml,粘贴在项目src下,内容如下
/user_list.jsp
(2)导入包:struts-2.2.1.1\apps\struts2-blank\web-inf\lib下的所有包,粘贴在lib下(3)配置web.xml文件:找到struts-2.2.1.1\apps\struts2-blank\web-inf\web.xml,复制其中的
……,粘贴在项目中的web.xml中,如:
struts2
org.apache.struts2.dispatcher.FilterDispatcher
struts2
/*

http://lihong11.iteye.com/blog/1917650