spring学习笔记 -- day13 基于XML的引入式整合
2017-08-21 13:48
267 查看
一、基于XML的引入式整合
1、明确什么是引入式
引入式整合就是把hibernate.cfg.xml中的配置都挪到spring的配置文件中,项目中没有hibernate.cfg.xml配置文件2、修改applicationContext-jdbc.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: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/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
<!-- 配置一个SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<!-- 1.连接数据库的信息 -->
<property name="dataSource" ref="dataSource"></property>
<!-- 2.hibernate的基本配置 -->
<property name="hibernateProperties">
<props>
<!-- 数据库的方言 -->
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<!-- 是否显示SQL语句 -->
<prop key="hibernate.show_sql">true</prop>
<!-- 是否格式化SQL语句 -->
<prop key="hibernate.format_sql">false</prop>
<!-- 选择生成DDL语句的策略 -->
<prop key="hibernate.hbm2ddl.auto">update</prop>
<!-- 把session绑定到当前线程上 -->
<prop key="hibernate.current_session_context_class">
org.springframework.orm.hibernate5.SpringSessionContext
</prop>
</props>
</property>
<!-- 3.映射文件的位置
mappingResources:
它是指定映射文件的位置,是一个数组类型的数据。它可以提供映射文件的位置。但是有几个映射文件,就需要写几个。
mappingDirectoryLocations:
它是指定映射文件所在的包,是一个数组类型的数据。它适合多个映射文件在不同的包下。指定的是包的名称。
mappingLocations:
它是指定映射文件的位置,是一个数据类型的数据。它可以使用通配符。指定的是映射文件的位置。(实际开发中选择此种方式较多)
-->
<property name="mappingLocations">
<array>
<value>classpath:cn/itcast/domain/*.hbm.xml</value>
</array>
</property>
</bean>
<!-- 配置数据源 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="com.mysql.jdbc.Driver"></property>
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/crm_ee247"></property>
<property name="user" value="root"></property>
<property name="password" value="1234"></property>
</bean>
</beans>
3、删除hibernate主配置文件
相关文章推荐
- spring学习笔记 -- day12 ssh整合之基于XML的独立式整合
- Spring学习笔记之二----基于XML的Spring AOP配置
- Spring4 学习笔记(3)-Spring 基于 XML 的方式配置 Bean
- spring学习笔记 -- day08 基于XML的Spring中的AOP
- Spring学习笔记之一----基于XML的Spring IOC配置
- spring学习笔记 -- day14 基于注解的整合
- Spring4学习笔记-Spring4整合Struts2(基于配置文件的方式)
- Spring4学习笔记-Spring4整合Struts2(基于配置文件的方式)
- springMVC学习笔记,SpringMV与web项目的整合(xml方式)
- Java与Flex学习笔记(7)----将Spring与Flex整合(基于嵌入式tomcat)(2012-07-24 更新)
- spring学习笔记12----Spring+jdbc组合开发( 采用基于xml方式配置事务)
- Spring MVC 学习笔记(一) 基于spring2.5的纯xml配置
- Spring4 学习笔记(3)-Spring 基于 XML 的方式配置 Bean(供自己学习)
- Spring MVC 学习笔记(一) 基于spring2.5的纯xml配置
- 基于Maven的Springboot项目搭建学习笔记
- Spring学习笔记(六)基于xml文件方式配置事物
- Spring boot 和 mybatis 学习笔记2--Mapper XML (静态)
- JavaWeb 学习笔记 spring+jdbc整合开发初步
- (基于Spring3)Spring学习笔记(二):BeanFactory 及其工作原理
- Spring4学习笔记-Spring4整合Hibernate4