Adapted to a signature change in Spring Data JPA. Improved test configuration and removed XML configuration completely. Upgraded to the latest Spring 3.2.x version.
This commit is contained in:
committed by
Oliver Gierke
parent
2344253eed
commit
19af936640
4
pom.xml
4
pom.xml
@@ -53,8 +53,8 @@
|
||||
</scm>
|
||||
|
||||
<properties>
|
||||
<spring.version>3.2.8.RELEASE</spring.version>
|
||||
<spring.data.jpa.version>1.5.2.RELEASE</spring.data.jpa.version>
|
||||
<spring.version>3.2.9.RELEASE</spring.version>
|
||||
<spring.data.jpa.version>1.6.0.RELEASE</spring.data.jpa.version>
|
||||
<slf4j.version>1.7.2</slf4j.version>
|
||||
<file.encoding>UTF-8</file.encoding>
|
||||
</properties>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012 the original author or authors.
|
||||
* Copyright 2012-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -22,10 +22,10 @@ import javax.persistence.EntityManager;
|
||||
import org.hibernate.envers.DefaultRevisionEntity;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.core.GenericTypeResolver;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.support.JpaEntityInformation;
|
||||
import org.springframework.data.jpa.repository.support.JpaRepositoryFactory;
|
||||
import org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean;
|
||||
import org.springframework.data.jpa.repository.support.SimpleJpaRepository;
|
||||
import org.springframework.data.repository.core.RepositoryMetadata;
|
||||
import org.springframework.data.repository.core.support.RepositoryFactorySupport;
|
||||
import org.springframework.data.repository.history.RevisionRepository;
|
||||
@@ -88,7 +88,7 @@ public class EnversRevisionRepositoryFactoryBean extends
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
protected <T, ID extends Serializable> JpaRepository<?, ?> getTargetRepository(RepositoryMetadata metadata,
|
||||
protected <T, ID extends Serializable> SimpleJpaRepository<?, ?> getTargetRepository(RepositoryMetadata metadata,
|
||||
EntityManager entityManager) {
|
||||
|
||||
JpaEntityInformation<T, Serializable> entityInformation = (JpaEntityInformation<T, Serializable>) getEntityInformation(metadata
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012 the original author or authors.
|
||||
* Copyright 2012-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,12 +19,13 @@ import java.sql.SQLException;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.hibernate.envers.strategy.ValidityAuditStrategy;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.envers.repository.support.EnversRevisionRepositoryFactoryBean;
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
|
||||
import org.springframework.orm.jpa.AbstractEntityManagerFactoryBean;
|
||||
@@ -40,6 +41,7 @@ import org.springframework.transaction.PlatformTransactionManager;
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@Configuration
|
||||
@EnableJpaRepositories(repositoryFactoryBeanClass = EnversRevisionRepositoryFactoryBean.class)
|
||||
public class Config {
|
||||
|
||||
@Bean
|
||||
@@ -49,13 +51,11 @@ public class Config {
|
||||
|
||||
@Bean
|
||||
public PlatformTransactionManager transactionManager() throws SQLException {
|
||||
|
||||
EntityManagerFactory entityManagerFactory = entityManagerFactoryBean().getObject();
|
||||
return new JpaTransactionManager(entityManagerFactory);
|
||||
return new JpaTransactionManager();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AbstractEntityManagerFactoryBean entityManagerFactoryBean() throws SQLException {
|
||||
public AbstractEntityManagerFactoryBean entityManagerFactory() throws SQLException {
|
||||
|
||||
HibernateJpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter();
|
||||
jpaVendorAdapter.setDatabase(Database.H2);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012 the original author or authors.
|
||||
* Copyright 2012-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -25,8 +25,6 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.ImportResource;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.envers.Config;
|
||||
@@ -38,7 +36,6 @@ import org.springframework.data.history.Revision;
|
||||
import org.springframework.data.history.Revisions;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||
|
||||
/**
|
||||
* Integration tests for repositories.
|
||||
@@ -46,19 +43,11 @@ import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(loader = AnnotationConfigContextLoader.class)
|
||||
@ContextConfiguration(classes = Config.class)
|
||||
public class RepositoryIntegrationTest {
|
||||
|
||||
@ImportResource("classpath:application-context.xml")
|
||||
@Configuration
|
||||
static class RepoConfig extends Config {
|
||||
|
||||
}
|
||||
|
||||
@Autowired
|
||||
LicenseRepository licenseRepository;
|
||||
@Autowired
|
||||
CountryRepository countryRepository;
|
||||
@Autowired LicenseRepository licenseRepository;
|
||||
@Autowired CountryRepository countryRepository;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
<?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:jpa="http://www.springframework.org/schema/data/jpa"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.0.xsd">
|
||||
|
||||
<jpa:repositories base-package="org.springframework.data.envers" factory-class="org.springframework.data.envers.repository.support.EnversRevisionRepositoryFactoryBean" />
|
||||
|
||||
</beans>
|
||||
Reference in New Issue
Block a user