#179 - Fixed build for multiple-datasources module after Spring Boot 1.4 upgrade.

We now explicitly disable DevToolsDataSourceAutoConfiguration as it currently expects exactly one DataSource being present.

Switched to Spring's @Transactional instead of the javax.transactional one.
This commit is contained in:
Oliver Gierke
2016-04-05 17:45:26 +02:00
parent b82460f33c
commit 4cc558e42e
3 changed files with 19 additions and 18 deletions

View File

@@ -15,6 +15,8 @@
*/
package example.springdata.jpa.multipleds;
import example.springdata.jpa.multipleds.customer.Customer.CustomerId;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
@@ -23,23 +25,27 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.devtools.autoconfigure.DevToolsDataSourceAutoConfiguration;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import example.springdata.jpa.multipleds.customer.Customer.CustomerId;
/**
* Core Spring Boot application configuration. Note, that we explicitly deactivate some auto-configurations explicitly.
* They mostly will even disable automatically if special bean names are used (e.g. {@code entityManagerFactory}) but I
* wanted to keep the two configurations symmetric. The configuration classes being located in separate packages serves
* the purpose of scoping the Spring Data repository scanning to those packages so that the infrastructure setup is
* attached to the corresponding repository instances.
* <p>
* {@link DevToolsDataSourceAutoConfiguration} is explicitly excluded until
* {@link https://github.com/spring-projects/spring-boot/issues/5540} is fixed.
* {@link https://github.com/spring-projects/spring-boot/issues/5541} has been filed to improve the need for manual
* exclusions in general.
*
* @author Oliver Gierke
* @see example.springdata.jpa.multipleds.customer.CustomerConfig
* @see example.springdata.jpa.multipleds.order.OrderConfig
*/
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class,
DataSourceTransactionManagerAutoConfiguration.class })
DataSourceTransactionManagerAutoConfiguration.class, DevToolsDataSourceAutoConfiguration.class })
@EnableTransactionManagement
public class Application {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2016 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.
@@ -18,10 +18,11 @@ package example.springdata.jpa.multipleds.customer;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import example.springdata.jpa.multipleds.Application;
import java.util.Optional;
import javax.persistence.EntityManager;
import javax.transaction.Transactional;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -29,9 +30,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.TransactionConfiguration;
import example.springdata.jpa.multipleds.Application;
import org.springframework.transaction.annotation.Transactional;
/**
* Integration test for {@link CustomerRepository}.
@@ -40,8 +39,7 @@ import example.springdata.jpa.multipleds.Application;
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class)
@Transactional
@TransactionConfiguration(transactionManager = "customerTransactionManager")
@Transactional(transactionManager = "customerTransactionManager")
public class CustomerRepositoryTests {
@Autowired CustomerRepository repository;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2016 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.
@@ -18,17 +18,15 @@ package example.springdata.jpa.multipleds.order;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import javax.transaction.Transactional;
import example.springdata.jpa.multipleds.Application;
import example.springdata.jpa.multipleds.customer.CustomerRepository;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.TransactionConfiguration;
import example.springdata.jpa.multipleds.Application;
import example.springdata.jpa.multipleds.customer.CustomerRepository;
import org.springframework.transaction.annotation.Transactional;
/**
* Integration test for {@link CustomerRepository}.
@@ -37,8 +35,7 @@ import example.springdata.jpa.multipleds.customer.CustomerRepository;
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class)
@Transactional
@TransactionConfiguration(transactionManager = "orderTransactionManager")
@Transactional(transactionManager = "orderTransactionManager")
public class OrderRepositoryTests {
@Autowired OrderRepository orders;