在另一篇文章hibernate5(2)初入门配置实例中,我们针对hibernate5.1版本的崭新引导配置方法,完成了对数据库的的插入实例操作,在本节内容中,我们开始引入spring4,完成spring4与hibernate5.1的整合工作,像数据库中插入一条记录。在后面学习hibernate中,我们都会使用spring来管理我们的Bean容器。
1. 导入spring4所需jar包
我们推荐使用maven来管理项目,下面是maven中的spring整合hibernate完整配置。
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<org.hibernate-version>5.1.0.Final</org.hibernate-version>
<!-- spring版本号 -->
<spring.version>4.0.2.RELEASE</spring.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.5</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.21</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2.2</version>
</dependency>
<!-- 导入dbcp的jar包,用来在applicationContext.xml中配置数据库 -->
<