一、整合步骤
1、搭建spring环境
1>加jar包
2>加入配置文件
注:搭完以后可以注入一个date测试一下看看搭建是否成功
2、spring管理hibernate
1>让spring管理数据库连接池
a.驱动 driverClass=oracle.jdbc.driver.OracleDriver
b.连接字符串 jdbcUrl=jdbc:oracle:thin:@localhost:1521:orcl
c.用户名 user=scott
d.密码 password=tiger
注:测试连接是否关闭
2>让spring管理sessionFactory
a.注入上面配置好的数据连接池
b.注入hibernate相关的
1.方言 dialect
2.是否显示sql show_sql
注:测试session是否开启
3>写po类
4>写配置文件
5>让sessionFactory管理po类
6>创建DAO
a.继承hibernatedaosupport
b.通过hibernatetemplate操作数据
注:sessionFactory是final修饰只能采用配置方式注入
3、spring管理struts2
1>搭建struts环境(jar包+配置文件)
2>加入struts2-spring-plugin-2.3.34.jar,创建spring-action.xml文件管理struts中的action
注:这个配置文件中的bean标签要用name不要用id,然后在struts中配置的时候要用bean中的name值
3>在web.xml中配值监听器来初始化spring容器
<!--web配置文件的位置-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring*.xml</param-value>
</context-param>
<!-- 加载配置文件的类 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
4>在spring.xml中开启注解(dao需要注入)