spring+struts2+hibernate整合

一、整合步骤

		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需要注入)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值