Spring+SpringMVC+Spring data JPA+Hibernate的jar包依赖以及JPA的Config配置
最近在学习Spring,没有听从前辈建议使用SpringBoot,在STS上直接new spring maven project,在配置jar包上吃了不少亏。下面我把以上所需的maven依赖以及配置Spring data JPA的Java类配置方式进行说明。
1、Maven配置
在配置Spring data JPA的jar包时,莫名其妙的出现一个异常:
java.lang.IllegalArgumentException:ResourceLoader must not be null!
执拙的我花了一下午的时间来处理这个异常,最后终于在google上找到了毛病:
原来是jpa的jar包版本与spring core的jar包版本冲突。
给Spring跪了。。。
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.irm</groupId>
<artifactId>lab</artifactId>
<name>Exam2</name>
<packaging>war</packaging>
<version>1.0.0-BUILD-SNAPSHOT</version>
<properties>
<java-version>1.6</java-version>
<org.springframework-version>4.3.0.RELEASE</org.springframework-version>
<org.aspectj-version>1.6.10</org.aspectj-version>
<org.slf4j-version>1.6.6</org.slf4j-version>
</properties>
<dependencies>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework-version}</version>
<exclusions>
<!-- Exclude Commons Logging in favor of SLF4j -->
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<!-- Spring and Transactions -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<!-- <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-commons</artifactId>
<version>1.13.7.RELEASE</version> </dependency> -->
<!-- jpa -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.6.0.RELEASE</version>
</dependency>
<!-- orm -->
<dependency>
<