最近發覺 spring-data-jpa 比較好用。
我在springcloud的項目中使用後,也嘗試在springmvc中增加 jpa。
一,創建moudle
選擇父項目,設定子項目名。
二,創建文件夾
創建文件夾,並且轉換文件夾類型
三,創建測試文件
在對應的java目錄下,創建包和controller
我的包路徑com.kintech.test.controller
Model
package com.kintech.model.domain.test;
import lombok.Data;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenericGenerator;
import javax.persistence.*;
/**
* @author Tyler
* @date 2020/4/20
*/
@Data
@Entity
@Table(name="testtab"
,catalog="kintech_pd"
)
@DynamicUpdate
public class TestTab {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="id")
private Integer id;
private String name;
}
Dao
@Repository("testtabdao")
public interface TestTabDao extends JpaRepository<TestTab,Integer> {
}
TestController(測試的話,直接略過service,調用dao。)
package com.kintech.test.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping("test")
public class TestController {
@RequestMapping(value = "test.do", method = RequestMethod.GET)
public @ResponseBody
String save(ModelMap mode){
return "hello test";
}
}
四,所有配置文件
下面比較多,大家看自己需求選擇對應的配置文件
然後我們一個個來看
①,jdbc.properties
注意自己的 mysql-connector-java 版本,
選擇 com.mysql.jdbc.Driver 還是 com.mysql.cj.jdbc.Driver
jdbc.driver = com.mysql.jdbc.Driver
jdbc.jdbcUrl=jdbc:mysql://localhost:3306/kintech_pd?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&autoReconnectForPools=true&noAccessToProcedureBodies=true
jdbc.user=xxx
jdbc.password=xxx
#jdbc.password=root
jdbc.initialPoolSize=3
jdbc.miniPoolSize=3
jdbc.maxPoolSize=20
jdbc.maxIdleTime=20
#hibernate config
hibernate.dialect = org.hibernate.dialect.MySQLDialect
hibernate.show_sql = false
hibernate.format_sql = true
#hibernate.hbm2ddl.auto =update
hibernate.hbm2ddl.auto =none
hibernate.cache.use_second_level_cache=false
hibernate.cache.use_query_cache=false
hibernate.cache.provider_class=net.sf.ehcache.hibernate.EhCacheProvider
hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory
②,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:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p"
xmlns:cache="http://www.springframework.org/schema/cache"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.3.xsd http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd"
default-lazy-init="true">
<!-- 引入屬性文件 -->
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:properties/env.properties</value>
<value>classpath:properties/jdbc.properties</value>
<value>classpath:properties/redis.properties</value>
</list>
</property>
</bean>
<!-- <context:annotation-config /> -->
<!-- 開啓自動掃描包 -->
<context:component-scan base-package="com.kintech" use-default-filters="true" annotation-config="true">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
<context:exclude-filter type="annotation" expression="org.springframework.web.bind.annotation.RestController"/>
</context:component-scan>
<import resource="spring-business.xml" />
<import resource="spring-redis.xml" />
<!-- 啓動緩存 -->
<cache:annotation-driven />
</beans>
③,spring-business.xml
注意<!-- JPA實體管理器工廠 -->開始的配置
<?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:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p" xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.3.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd"
default-lazy-init="true">
<!--配置數據源-->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="${jdbc.driver}" /> <!--數據庫連接驅動-->
<property name="jdbcUrl" value="${jdbc.jdbcUrl}" /> <!--數據庫地址-->
<property name="user" value="${jdbc.user}" /> <!--用戶名-->
<property name="password" value="${jdbc.password}" /> <!--密碼-->
<property name="maxPoolSize" value="${jdbc.maxPoolSize}" /> <!--最大連接數-->
<property name="minPoolSize" value="${jdbc.miniPoolSize}" /> <!--最小連接數-->
<property name="initialPoolSize" value="${jdbc.initialPoolSize}" /> <!--初始化連接池內的數據庫連接-->
<property name="maxIdleTime" value="${jdbc.maxIdleTime}" /> <!--最大空閒時間-->
</bean>
<!--配置session工廠-->
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="com.kintech.model" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop> <!--hibernate根據實體自動生成數據庫表-->
<prop key="hibernate.dialect">${hibernate.dialect}</prop> <!--指定數據庫方言-->
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop> <!--在控制檯顯示執行的數據庫操作語句-->
<prop key="hibernate.format_sql">${hibernate.format_sql}</prop> <!--在控制檯顯示執行的數據哭操作語句(格式)-->
<prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop>
<prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop> <!-- 查詢緩存 -->
<prop key="hibernate.cache.provider_class">${hibernate.cache.provider_class}</prop>
<prop key="hibernate.cache.region.factory_class">${hibernate.cache.region.factory_class}</prop>
</props>
</property>
</bean>
<!-- JPA實體管理器工廠 -->
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter" ref="hibernateJpaVendorAdapter" />
<!-- 加入定製化包路徑 -->
<property name="packagesToScan" value="com.kintech.model.domain.test" />
<property name="jpaProperties">
<props>
<prop key="hibernate.current_session_context_class">thread</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop><!-- validate/update/create -->
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<!-- 建表的命名規則 -->
<prop key="hibernate.ejb.naming_strategy">org.hibernate.cfg.ImprovedNamingStrategy</prop>
</props>
</property>
</bean>
<!-- 設置JPA實現廠商的特定屬性 -->
<bean id="hibernateJpaVendorAdapter"
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="databasePlatform" value="${hibernate.dialect}"/>
</bean>
<!-- Jpa 事務配置 -->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<!-- Spring Data Jpa配置 -->
<jpa:repositories base-package="com.kintech.dao" transaction-manager-ref="transactionManager" entity-manager-factory-ref="entityManagerFactory"/>
<!-- 使用annotation定義事務 -->
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" />
</beans>
④,spring-redis.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:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.3.xsd"
default-lazy-init="true" >
<!--redis配置 -->
<bean name="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig" lazy-init="true">
<property name="maxTotal" value="${redis.maxTotal}"/>
<property name="maxIdle" value="${redis.maxIdle}"/>
<property name="minIdle" value="${redis.minIdle}"/>
<property name="maxWaitMillis" value="${redis.maxWaitMillis}"/>
<property name="testOnBorrow" value="${redis.testOnBorrow}"/>
<property name="testOnReturn" value="${redis.testOnReturn}"/>
<property name="testWhileIdle" value="${redis.testWhileIdle}"/>
<property name="timeBetweenEvictionRunsMillis" value="${redis.timeBetweenEvictionRunsMillis}"/>
<property name="numTestsPerEvictionRun" value="${redis.numTestsPerEvictionRun}"/>
<property name="minEvictableIdleTimeMillis" value="${redis.minEvictableIdleTimeMillis}"/>
</bean>
<!-- Jedis ConnectionFactory 數據庫連接配置-->
<bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<property name="hostName" value="${redis.host}" />
<property name="port" value="${redis.port}" />
<property name="password" value="${redis.password}" />
<property name="database" value="${redis.database}" />
<property name="poolConfig" ref="jedisPoolConfig" />
<property name="timeout" value="${redis.timeOut}" />
</bean>
<!-- StringRedisTemplate 序列化方式 -->
<bean id="redisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate" p:connection-factory-ref="jedisConnectionFactory" >
<!--以String類型的方式 序列化 時間:2020年2月13日17:29:41 作者:陳翔宇 start -->
<property name="keySerializer">
<bean class="org.springframework.data.redis.serializer.StringRedisSerializer" />
</property>
<property name="valueSerializer">
<bean class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" />
</property>
<property name="hashKeySerializer">
<bean class="org.springframework.data.redis.serializer.StringRedisSerializer" />
</property>
<property name="hashValueSerializer">
<bean class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" />
</property>
<!--以String類型的方式 序列化 時間:2020年2月13日17:29:41 作者:陳翔宇 end -->
</bean>
<!-- 設置Cookie domain 和 名稱 -->
<bean id="defaultCookieSerializer" class="com.kintech.web.CookieSerializer">
<property name="domainName" value="${sysHost}"/>
<property name="cookieName" value="MYJSESSIONID"/>
<!--<property name="domainNamePattern" value="^.+?\\.(\\w+\\.[a-z]+)$"/>-->
</bean>
<!-- 將session放入redis -->
<bean id="redisHttpSessionConfiguration"
class="org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration">
<property name="maxInactiveIntervalInSeconds" value="7200" />
<property name="cookieSerializer" ref="defaultCookieSerializer"/>
</bean>
<!--@Cacheable使用Redis緩存 : spring自己的緩存管理器,這裏定義了緩存位置名稱 ,即註解中的value -->
<bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager">
<property name="caches">
<set>
<bean class="org.springframework.data.redis.cache.RedisCache">
<constructor-arg name="redisOperations" ref="redisTemplate"></constructor-arg>
<constructor-arg name="name" value="menuAllList"></constructor-arg>
<constructor-arg name="prefix" value="dbSYS:"></constructor-arg>
<constructor-arg name="expiration" value="7200"></constructor-arg>
</bean>
<bean class="org.springframework.data.redis.cache.RedisCache">
<constructor-arg name="redisOperations" ref="redisTemplate"></constructor-arg>
<constructor-arg name="name" value="accesscodeAllList"></constructor-arg>
<constructor-arg name="prefix" value="dbSYS:"></constructor-arg>
<constructor-arg name="expiration" value="7200"></constructor-arg>
</bean>
<bean class="org.springframework.data.redis.cache.RedisCache">
<constructor-arg name="redisOperations" ref="redisTemplate"></constructor-arg>
<constructor-arg name="name" value="afTypeAllList"></constructor-arg>
<constructor-arg name="prefix" value="dbAF:"></constructor-arg>
<constructor-arg name="expiration" value="7200"></constructor-arg>
</bean>
</set>
</property>
</bean>
</beans>
⑤,springmvc-servlet.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:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.3.xsd"
default-lazy-init="true" >
<!-- 默認的註解映射的支持 -->
<mvc:annotation-driven />
<!--靜態資源映射 -->
<mvc:default-servlet-handler />
<!-- 掃描Controller -->
<context:component-scan base-package="com.kintech" use-default-filters="false">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
<context:include-filter type="annotation" expression="org.springframework.web.bind.annotation.RestController" />
</context:component-scan>
<!-- 引入屬性文件 -->
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:properties/env.properties</value>
</list>
</property>
</bean>
<!-- JSP視圖文件解析配置 -->
<bean id="urlBasedViewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="prefix" value="/WEB-INF/view/" />
<property name="suffix" value=".jsp" />
<!-- <property name="viewClass" value="org.springframework.web.servlet.view.InternalResourceView"
/> -->
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
</bean>
<!-- 上傳文件攔截,設置最大上傳文件大小 10M=10*1024*1024(B)=10485760 bytes -->
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize">
<value>104857600</value>
</property>
<property name="maxInMemorySize" value="20480" />
<property name="defaultEncoding" value="UTF-8" />
<property name="resolveLazily" value="true" />
</bean>
<!-- 消息轉換器 -->
<mvc:annotation-driven>
<mvc:message-converters>
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="defaultCharset" value="UTF-8" />
</bean>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="objectMapper">
<bean class="com.kintech.common.MyObjectMapper" />
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
<!-- mvc Exception handler -->
<bean id="handlerExceptionResolver"
class="com.kintech.web.AnnotationHandlerMethodExceptionResolver">
<property name="defaultErrorView" value="error/500" /> <!--500錯誤頁面 -->
<property name="defaultErrorView403" value="error/403" /> <!--403錯誤頁面 -->
<property name="messageConverters">
<list>
<bean
class="org.springframework.http.converter.ByteArrayHttpMessageConverter" />
<!-- JSON轉換器無需設置mediaType,由外部客戶端調用時,手動設置相關mediaType -->
<bean
class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" />
</list>
</property>
</bean>
<!-- aop日誌 -->
<aop:aspectj-autoproxy proxy-target-class="true" />
<bean id="logAopAction" class="com.kintech.web.SysLog.LogAopAction" />
<!-- 配置國際化資源文件路徑 -->
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename">
<!-- 定義消息資源文件的相對路徑 -->
<value>languages/lang</value>
</property>
</bean>
<bean id="localeResolver"
class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
<property name="cookieMaxAge" value="604800" />
<property name="defaultLocale" value="${defaultLocale}" />
<property name="cookieName" value="language"></property>
</bean>
</beans>
⑥,web.xml
沒什麼太大花頭,就是呸呸呸。。。
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
<display-name>test</display-name>
<description>test</description>
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>test.root</param-value>
</context-param>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:log4j/log4j.properties</param-value>
</context-param>
<context-param>
<param-name>log4jRefreshInterval</param-name>
<param-value>6000</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener
</listener-class>
</listener>
<listener>
<description>spring監聽器</description>
<listener-class>org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<listener>
<description>防止內存泄露</description>
<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
<filter>
<filter-name>springSessionRepositoryFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSessionRepositoryFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
<filter>
<filter-name>characterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter
</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>test</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/springmvc-servlet.xml</param-value>
</init-param>
<init-param>
<param-name>detectAllHandlerExceptionResolvers</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>test</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>120</session-timeout>
<tracking-mode>COOKIE</tracking-mode>
</session-config>
</web-app>
⑦,pom文件
主要是JPA註釋這一塊,注意順序
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.kintech</groupId>
<artifactId>kintech.parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>kintech.test</artifactId>
<packaging>war</packaging>
<name>kintech.test</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>com.kintech</groupId>
<artifactId>kintech.web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<!-- JPA -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.4.12.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.4.12.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>5.0.5.Final</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.11.13.RELEASE</version>
</dependency>
<!-- JPA -->
</dependencies>
</project>
五,測試