Skip to content

Commit 622606d

Browse files
committed
Make it clearer that only the main DataSource bean may be replaced
Closes gh-23808
1 parent d32d65b commit 622606d

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jdbc/AutoConfigureTestDatabase.java

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -29,10 +29,13 @@
2929
import org.springframework.boot.jdbc.EmbeddedDatabaseConnection;
3030
import org.springframework.boot.test.autoconfigure.properties.PropertyMapping;
3131
import org.springframework.boot.test.autoconfigure.properties.SkipPropertyMapping;
32+
import org.springframework.context.annotation.Primary;
3233

3334
/**
3435
* Annotation that can be applied to a test class to configure a test database to use
35-
* instead of any application defined or auto-configured {@link DataSource}.
36+
* instead of the application-defined or auto-configured {@link DataSource}. In the case
37+
* of multiple {@code DataSource} beans, only the {@link Primary @Primary}
38+
* {@code DataSource} is considered.
3639
*
3740
* @author Phillip Webb
3841
* @since 1.5.0
@@ -47,15 +50,16 @@
4750
public @interface AutoConfigureTestDatabase {
4851

4952
/**
50-
* Determines what type of existing DataSource beans can be replaced.
53+
* Determines what type of existing DataSource bean can be replaced.
5154
* @return the type of existing DataSource to replace
5255
*/
5356
@PropertyMapping(skip = SkipPropertyMapping.ON_DEFAULT_VALUE)
5457
Replace replace() default Replace.ANY;
5558

5659
/**
57-
* The type of connection to be established when {@link #replace() replacing} the data
58-
* source. By default will attempt to detect the connection based on the classpath.
60+
* The type of connection to be established when {@link #replace() replacing} the
61+
* DataSource. By default will attempt to detect the connection based on the
62+
* classpath.
5963
* @return the type of connection to use
6064
*/
6165
EmbeddedDatabaseConnection connection() default EmbeddedDatabaseConnection.NONE;
@@ -66,12 +70,12 @@
6670
enum Replace {
6771

6872
/**
69-
* Replace any DataSource bean (auto-configured or manually defined).
73+
* Replace the DataSource bean whether it was auto-configured or manually defined.
7074
*/
7175
ANY,
7276

7377
/**
74-
* Only replace auto-configured DataSource.
78+
* Only replace the DataSource if it was auto-configured.
7579
*/
7680
AUTO_CONFIGURED,
7781

0 commit comments

Comments
 (0)