--------------------siwuxie095

SSH 框架整合的其它方式

1、主要是整合 Spring 框架和 Hibernate 框架时,可以不写

Hibernate 核心配置文件:hibernate.cfg.xml

2、把 Hibernate 核心配置文件中的配置全都转移到 Spring

核心配置文件中

3、具体实现

applicationContext.xml:

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:aop="http://www.springframework.org/schema/aop"

xmlns:context="http://www.springframework.org/schema/context"

xmlns:tx="http://www.springframework.org/schema/tx"

xsi:schemaLocation="

http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans.xsd

http://www.springframework.org/schema/aop

http://www.springframework.org/schema/aop/spring-aop.xsd

http://www.springframework.org/schema/context

http://www.springframework.org/schema/context/spring-context.xsd

http://www.springframework.org/schema/tx

http://www.springframework.org/schema/tx/spring-tx.xsd">

<!-- (1) -->

<!-- 配置 C3P0 连接池 -->

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">

<property name="driverClass" value="com.mysql.jdbc.Driver"/>

<!--

jdbc:mysql:///test_db 是 jdbc:mysql://localhost:3306/test_db 的简写

-->

<property name="jdbcUrl" value="jdbc:mysql:///test_db"/>

<property name="user" value="root"/>

<property name="password" value="8888"/>

</bean>

<!-- SessionFactory 对象的创建交给 Spring 进行管理 -->

<bean id="sessionFactory"

class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">

<!--

数据库配置原本是在 Hibernate 核心配置文件中配置的,

现在 Hibernate 核心配置文件不存在了,所以在这里注

入 dataSource

LocalSessionFactoryBean 中有相关属性,所以可以

注入

-->

<property name="dataSource" ref="dataSource"></property>

<!-- 配置 Hibernate 基本信息 -->

<property name="hibernateProperties">

<props>

<prop key="hibernate.show_sql">true</prop>

<prop key="hibernate.format_sql">true</prop>

<prop key="hibernate.hbm2ddl.auto">update</prop>

<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>

<!--

原来的配置:

<prop key="hibernate.current_session_context_class">thread</prop>

在 SSH 框架整合中会报错,要么将这个配置删了,要么改成如下配置

参考链接:http://blog.csdn.net/maoyuanming0806/article/details/61417995

-->

<prop key="hibernate.current_session_context_class">

org.springframework.orm.hibernate5.SpringSessionContext

</prop>

</props>

</property>

<!-- 引入映射配置文件 -->

<property name="mappingResources">

<list>

<value>com/siwuxie095/entity/User.hbm.xml</value>

<!-- <value>....</value> -->

</list>

</property>

</bean>

<!-- (2) -->

<!-- 配置 Action 对象 -->

<bean id="userAction" class="com.siwuxie095.action.UserAction" scope="prototype">

<property name="userService" ref="userService"></property>

</bean>

<!-- 配置 Service 对象 -->

<bean id="userService" class="com.siwuxie095.service.UserService">

<property name="userDao" ref="userDaoImpl"></property>

</bean>

<!-- 配置 Dao 实现类对象 -->

<bean id="userDaoImpl" class="com.siwuxie095.dao.impl.UserDaoImpl">

<property name="hibernateTemplate" ref="hibernateTemplate"></property>

</bean>

<!-- 配置 HibernateTemplate 对象 -->

<bean id="hibernateTemplate" class="org.springframework.orm.hibernate5.HibernateTemplate">

<!-- 注入 SessionFactory 对象 -->

<property name="sessionFactory" ref="sessionFactory"></property>

</bean>

<!-- (3) -->

<!-- 配置事务管理器 HibernateTransactionManager -->

<bean id="transactionManager"

class="org.springframework.orm.hibernate5.HibernateTransactionManager">

<!--注入 SessionFactory 对象 -->

<property name="sessionFactory" ref="sessionFactory"></property>

</bean>

<!-- 开启事务注解 -->

<tx:annotation-driven transaction-manager="transactionManager"/>

</beans>

【made by siwuxie095】

SSH框架整合的其它方式的更多相关文章

  1. SSH框架整合

    SSH框架整合 一.原理图 action:(struts2) 1.获取表单的数据 2.表单的验证,例如非空验证,email验证等 3.调用service,并把数据传递给service Service: ...

  2. Spring+Hibernate+Struts(SSH)框架整合

    SSH框架整合 前言:有人说,现在还是流行主流框架,SSM都出来很久了,更不要说SSH.我不以为然.现在许多公司所用的老项目还是ssh,如果改成流行框架,需要成本.比如金融IT这一块,数据库dao层还 ...

  3. MVC+Spring.NET+NHibernate .NET SSH框架整合 C# 委托异步 和 async /await 两种实现的异步 如何消除点击按钮时周围出现的白线? Linq中 AsQueryable(), AsEnumerable()和ToList()的区别和用法

    MVC+Spring.NET+NHibernate .NET SSH框架整合   在JAVA中,SSH框架可谓是无人不晓,就和.NET中的MVC框架一样普及.作为一个初学者,可以感受到.NET出了MV ...

  4. SSH框架整合过程总结

    ---------------------siwuxie095                                 SSH 框架整合过程总结         (一)导入相关 jar 包(共 ...

  5. SSH 框架整合总结

    1. 搭建Struts2 环境 创建 struts2 的配置文件: struts.xml; 在 web.xml 中配置 struts2 的核心过滤器; // struts.xml <?xml v ...

  6. dwr与ssh框架整合教程

    (1)dwr与ssh框架整合教程dwr框架介绍. DWR(Direct Web Remoting)是一个用于改善web页面与Java类交互的远程服务器端Ajax开源框架,可以帮助开 发人员开发包含AJ ...

  7. ssh框架整合之登录以及增删改查

    1.首先阐述一下我用得开发工具,myeclipse2017+oracle,所以我的基本配置步骤可能不一样,下面我用几张图来详解我的开发步骤. ---1先配置structs (Target 选择apac ...

  8. J2EE进阶(十)SSH框架整合常见问题汇总(一)

    SSH框架整合常见问题汇总(一) 前言 以下所列问题具有针对性,但是遇到同类型问题时均可按照此思路进行解决. HTTP Status 404 - No result defined for actio ...

  9. SSM框架整合的其它方式

    ---------------------siwuxie095                                 SSM 框架整合的其它方式         1.主要是整合 Spring ...

随机推荐

  1. 比较java枚举成员使用equal还是==

    问题 我知道Java枚举会被编译成一个包含私有构造参数和一堆静态方法的类,当去比较两个枚举的时候,总是使用equals()方法,例如: public useEnums(SomeEnum a) { if ...

  2. unity3d的碰撞检测及trigger

    A.基本概念 要产生碰撞必须为游戏对象添加刚体(Rigidbody)和碰撞器,刚体可以让物体在物理影响下运动.碰撞体是物理组件的一类,它要与刚体一起添加到游戏对象上才能触发碰撞.如果两个刚体相互撞在一 ...

  3. Spark分析之MemoryStore

    private case class MemoryEntry(value: Any, size: Long, deserialized: Boolean) class MemoryStore(bloc ...

  4. 布尔值运算&集合

    示例:返回booleanli = [] li = {} li = () if not li: print(1) radiansdict.has_key(key) #如果键在字典dict里返回true, ...

  5. mybatis Dynamic SQL动态 SQL

    动态 SQL MyBatis 的强大特性之一便是它的动态 SQL.如果你有使用 JDBC 或其它类似框架的经验,你就能体会到根据不同条件拼接 SQL 语句的痛苦.例如拼接时要确保不能忘记添加必要的空格 ...

  6. python 字符串与字节之间的相互转化

    1.将字符串转化成字节 b'fffff' bytes('ffff', encoding='utf-8') 'ffff'.encode('utf-8') 2.将字节转化成字符串 str(data, en ...

  7. 支持向量机(理论+opencv实现)

    从基础开始讲起,没有这些东西看支持向量机真的很难!   1.拉格朗日乘子(Lagrangemultiplier)   假设需要求极值的目标函数(objectivefunction)为f(x,y),限制 ...

  8. png-CRC32校验

    官方文档: https://www.w3.org/TR/PNG-CRCAppendix.html CRC32校验的数据,看原文 A four-byte CRC (Cyclic Redundancy C ...

  9. jquery函数写法

    普通jquery函数写法 <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script&g ...

  10. zabbix监控windows系统CPU使用率

    参考网站:https://blog.csdn.net/reblue520/article/details/76287113 Zabbix 自带的模块没有 CPU 使用率(百分比)这个监控项,我们可以通 ...