<?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"
xmlns:context="http://www.springframework.org/schema/context"
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
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<!-- 数据源:c3p0-->
<bean id="myDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driverClass}"></property>
<property name="jdbcUrl" value="${jdbc.url}"></property>
<property name="user" value="${jdbc.username}"></property>
<property name="password" value="${jdbc.password}"></property>
</bean>
<!-- 注册jdbc.properties文件 -->
<context:property-placeholder location="classpath:jdbc.properties"/>
<!-- 注册sessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="dataSource" ref="myDataSource"/>
<property name="packagesToScan" value="com.layne.beans"/>
<property name="hibernateProperties">
<props>
<!-- 当前session上下文 -->
<prop key="hibernate.current_session_context_class">org.springframework.orm.hibernate5.SpringSessionContext
</prop>
<!-- 方言 -->
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect
</prop>
<!-- 自动建表 -->
<prop key="hibernate.hbm2ddl.auto">update
</prop>
<!--显示SQL语句 -->
<prop key="hibernate.show_sql">true
</prop>
<!-- SQL语句格式化 -->
<prop key="hibernate.format_sql">true
</prop>
</props>
</property>
</bean>
<!-- 扫描 -->
<context:component-scan base-package="com.layne"/>
<!-- 注册事物管理器 -->
<bean id="hibernateTransactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- 使用注解配置事物:事物驱动注册 -->
<tx:annotation-driven transaction-manager="hibernateTransactionManager"/>
</beans>
数据库访问资源文件:
jdbc.driverClass=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/test
jdbc.username=root
jdbc.password=
项目结构树:
jar包地址:http://download.csdn.net/download/lg_xulei/10028827
该项目使用EasyUI插件。
资源下载地址:http://download.csdn.net/download/lg_xulei/10131521
转载于:https://www.cnblogs.com/flytogalaxy/p/7890987.html
相关资源:SSH框架整合实例