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
dc566086
Commit
dc566086
authored
Apr 17, 2020
by
Phillip Webb
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.2.x'
Closes gh-21004
parents
619fe38d
1a8aa72a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
2 deletions
+23
-2
DataSourceAutoConfiguration.java
.../boot/autoconfigure/jdbc/DataSourceAutoConfiguration.java
+16
-2
DataSourceAutoConfigurationTests.java
.../autoconfigure/jdbc/DataSourceAutoConfigurationTests.java
+7
-0
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration.java
View file @
dc566086
...
@@ -36,8 +36,10 @@ import org.springframework.context.annotation.ConditionContext;
...
@@ -36,8 +36,10 @@ import org.springframework.context.annotation.ConditionContext;
import
org.springframework.context.annotation.Conditional
;
import
org.springframework.context.annotation.Conditional
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.core.env.Environment
;
import
org.springframework.core.type.AnnotatedTypeMetadata
;
import
org.springframework.core.type.AnnotatedTypeMetadata
;
import
org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType
;
import
org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType
;
import
org.springframework.util.StringUtils
;
/**
/**
* {@link EnableAutoConfiguration Auto-configuration} for {@link DataSource}.
* {@link EnableAutoConfiguration Auto-configuration} for {@link DataSource}.
...
@@ -125,8 +127,7 @@ public class DataSourceAutoConfiguration {
...
@@ -125,8 +127,7 @@ public class DataSourceAutoConfiguration {
@Override
@Override
public
ConditionOutcome
getMatchOutcome
(
ConditionContext
context
,
AnnotatedTypeMetadata
metadata
)
{
public
ConditionOutcome
getMatchOutcome
(
ConditionContext
context
,
AnnotatedTypeMetadata
metadata
)
{
ConditionMessage
.
Builder
message
=
ConditionMessage
.
forCondition
(
"EmbeddedDataSource"
);
ConditionMessage
.
Builder
message
=
ConditionMessage
.
forCondition
(
"EmbeddedDataSource"
);
boolean
hasDatasourceUrl
=
context
.
getEnvironment
().
containsProperty
(
DATASOURCE_URL_PROPERTY
);
if
(
hasDataSourceUrlProperty
(
context
))
{
if
(
hasDatasourceUrl
)
{
return
ConditionOutcome
.
noMatch
(
message
.
because
(
DATASOURCE_URL_PROPERTY
+
" is set"
));
return
ConditionOutcome
.
noMatch
(
message
.
because
(
DATASOURCE_URL_PROPERTY
+
" is set"
));
}
}
if
(
anyMatches
(
context
,
metadata
,
this
.
pooledCondition
))
{
if
(
anyMatches
(
context
,
metadata
,
this
.
pooledCondition
))
{
...
@@ -139,6 +140,19 @@ public class DataSourceAutoConfiguration {
...
@@ -139,6 +140,19 @@ public class DataSourceAutoConfiguration {
return
ConditionOutcome
.
match
(
message
.
found
(
"embedded database"
).
items
(
type
));
return
ConditionOutcome
.
match
(
message
.
found
(
"embedded database"
).
items
(
type
));
}
}
private
boolean
hasDataSourceUrlProperty
(
ConditionContext
context
)
{
Environment
environment
=
context
.
getEnvironment
();
if
(
environment
.
containsProperty
(
DATASOURCE_URL_PROPERTY
))
{
try
{
return
StringUtils
.
hasText
(
environment
.
getProperty
(
DATASOURCE_URL_PROPERTY
));
}
catch
(
IllegalArgumentException
ex
)
{
// Ignore unresolvable placeholder errors
}
}
return
false
;
}
}
}
}
}
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfigurationTests.java
View file @
dc566086
...
@@ -49,6 +49,7 @@ import org.springframework.context.annotation.Bean;
...
@@ -49,6 +49,7 @@ import org.springframework.context.annotation.Bean;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.jdbc.datasource.SimpleDriverDataSource
;
import
org.springframework.jdbc.datasource.SimpleDriverDataSource
;
import
org.springframework.jdbc.datasource.embedded.EmbeddedDatabase
;
import
org.springframework.util.StringUtils
;
import
org.springframework.util.StringUtils
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
...
@@ -209,6 +210,12 @@ class DataSourceAutoConfigurationTests {
...
@@ -209,6 +210,12 @@ class DataSourceAutoConfigurationTests {
.
run
((
context
)
->
assertThat
(
context
).
getBean
(
DataSource
.
class
).
isInstanceOf
(
BasicDataSource
.
class
));
.
run
((
context
)
->
assertThat
(
context
).
getBean
(
DataSource
.
class
).
isInstanceOf
(
BasicDataSource
.
class
));
}
}
@Test
void
whenThereIsAnEmptyUserProvidedDataSource
()
{
this
.
contextRunner
.
with
(
hideConnectionPools
()).
withPropertyValues
(
"spring.datasource.url:"
)
.
run
((
context
)
->
assertThat
(
context
).
getBean
(
DataSource
.
class
).
isInstanceOf
(
EmbeddedDatabase
.
class
));
}
@Test
@Test
void
testDataSourceIsInitializedEarly
()
{
void
testDataSourceIsInitializedEarly
()
{
this
.
contextRunner
.
withUserConfiguration
(
TestInitializedDataSourceConfiguration
.
class
)
this
.
contextRunner
.
withUserConfiguration
(
TestInitializedDataSourceConfiguration
.
class
)
...
...
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