Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
1d601840
Commit
1d601840
authored
Feb 18, 2020
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.1.x' into 2.2.x
Closes gh-20217
parents
e59d3fbb
2147976c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
6 deletions
+21
-6
DataSourceAutoConfiguration.java
.../boot/autoconfigure/jdbc/DataSourceAutoConfiguration.java
+6
-1
DataSourceAutoConfigurationTests.java
.../autoconfigure/jdbc/DataSourceAutoConfigurationTests.java
+15
-5
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration.java
View file @
1d601840
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
...
@@ -38,6 +38,7 @@ import org.springframework.context.annotation.Configuration;
import
org.springframework.context.annotation.Import
;
import
org.springframework.core.type.AnnotatedTypeMetadata
;
import
org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType
;
import
org.springframework.util.StringUtils
;
/**
* {@link EnableAutoConfiguration Auto-configuration} for {@link DataSource}.
...
...
@@ -122,6 +123,10 @@ public class DataSourceAutoConfiguration {
@Override
public
ConditionOutcome
getMatchOutcome
(
ConditionContext
context
,
AnnotatedTypeMetadata
metadata
)
{
ConditionMessage
.
Builder
message
=
ConditionMessage
.
forCondition
(
"EmbeddedDataSource"
);
String
url
=
context
.
getEnvironment
().
getProperty
(
"spring.datasource.url"
);
if
(
StringUtils
.
hasText
(
url
))
{
return
ConditionOutcome
.
noMatch
(
message
.
found
(
"explicit url"
).
items
(
url
));
}
if
(
anyMatches
(
context
,
metadata
,
this
.
pooledCondition
))
{
return
ConditionOutcome
.
noMatch
(
message
.
foundExactly
(
"supported pooled data source"
));
}
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfigurationTests.java
View file @
1d601840
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
...
@@ -27,6 +27,7 @@ import java.util.List;
import
java.util.Properties
;
import
java.util.Random
;
import
java.util.function.Consumer
;
import
java.util.function.Function
;
import
java.util.logging.Logger
;
import
javax.sql.DataSource
;
...
...
@@ -143,15 +144,19 @@ class DataSourceAutoConfigurationTests {
});
}
@Test
void
dataSourceWhenNoConnectionPoolsAreAvailableWithUrlDoesNotCreateDataSource
()
{
this
.
contextRunner
.
with
(
hideConnectionPools
())
.
run
((
context
)
->
assertThat
(
context
).
doesNotHaveBean
(
DataSource
.
class
));
}
/**
* This test makes sure that if no supported data source is present, a datasource is
* still created if "spring.datasource.type" is present.
*/
@Test
void
explicitTypeNoSupportedDataSource
()
{
this
.
contextRunner
.
withClassLoader
(
new
FilteredClassLoader
(
"org.apache.tomcat"
,
"com.zaxxer.hikari"
,
"org.apache.commons.dbcp"
,
"org.apache.commons.dbcp2"
))
void
dataSourceWhenNoConnectionPoolsAreAvailableWithUrlAndTypeCreatesDataSource
()
{
this
.
contextRunner
.
with
(
hideConnectionPools
())
.
withPropertyValues
(
"spring.datasource.driverClassName:org.hsqldb.jdbcDriver"
,
"spring.datasource.url:jdbc:hsqldb:mem:testdb"
,
"spring.datasource.type:"
+
SimpleDriverDataSource
.
class
.
getName
())
...
...
@@ -197,6 +202,11 @@ class DataSourceAutoConfigurationTests {
.
isTrue
());
}
private
static
Function
<
ApplicationContextRunner
,
ApplicationContextRunner
>
hideConnectionPools
()
{
return
(
runner
)
->
runner
.
withClassLoader
(
new
FilteredClassLoader
(
"org.apache.tomcat"
,
"com.zaxxer.hikari"
,
"org.apache.commons.dbcp"
,
"org.apache.commons.dbcp2"
));
}
private
<
T
extends
DataSource
>
void
assertDataSource
(
Class
<
T
>
expectedType
,
List
<
String
>
hiddenPackages
,
Consumer
<
T
>
consumer
)
{
FilteredClassLoader
classLoader
=
new
FilteredClassLoader
(
StringUtils
.
toStringArray
(
hiddenPackages
));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment