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
7c54c3ff
Commit
7c54c3ff
authored
Aug 12, 2016
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure that @LiquibaseDataSource is preferred to “normal” DataSource
Closes gh-6604
parent
8424965a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
7 deletions
+16
-7
LiquibaseAutoConfiguration.java
...t/autoconfigure/liquibase/LiquibaseAutoConfiguration.java
+4
-4
LiquibaseDataSource.java
...ork/boot/autoconfigure/liquibase/LiquibaseDataSource.java
+2
-2
LiquibaseAutoConfigurationTests.java
...oconfigure/liquibase/LiquibaseAutoConfigurationTests.java
+10
-1
No files found.
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration.java
View file @
7c54c3ff
...
@@ -116,12 +116,12 @@ public class LiquibaseAutoConfiguration {
...
@@ -116,12 +116,12 @@ public class LiquibaseAutoConfiguration {
}
}
private
DataSource
getDataSource
()
{
private
DataSource
getDataSource
()
{
if
(
this
.
properties
.
getUrl
()
==
null
)
{
if
(
this
.
liquibaseDataSource
!=
null
)
{
return
this
.
dataSource
;
}
else
if
(
this
.
liquibaseDataSource
!=
null
)
{
return
this
.
liquibaseDataSource
;
return
this
.
liquibaseDataSource
;
}
}
else
if
(
this
.
properties
.
getUrl
()
==
null
)
{
return
this
.
dataSource
;
}
return
DataSourceBuilder
.
create
().
url
(
this
.
properties
.
getUrl
())
return
DataSourceBuilder
.
create
().
url
(
this
.
properties
.
getUrl
())
.
username
(
this
.
properties
.
getUser
())
.
username
(
this
.
properties
.
getUser
())
.
password
(
this
.
properties
.
getPassword
()).
build
();
.
password
(
this
.
properties
.
getPassword
()).
build
();
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseDataSource.java
View file @
7c54c3ff
...
@@ -25,8 +25,8 @@ import java.lang.annotation.Target;
...
@@ -25,8 +25,8 @@ import java.lang.annotation.Target;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Qualifier
;
/**
/**
* Qualifier annotation for a DataSource to be injected in to Liquibase. If used for a
second
* Qualifier annotation for a DataSource to be injected in to Liquibase. If used for a
* data source, the other (main) one would normally be marked as {@code @Primary}.
*
second
data source, the other (main) one would normally be marked as {@code @Primary}.
*
*
* @author Eddú Meléndez
* @author Eddú Meléndez
* @since 1.4.1
* @since 1.4.1
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfigurationTests.java
View file @
7c54c3ff
...
@@ -38,6 +38,7 @@ import org.springframework.boot.test.util.EnvironmentTestUtils;
...
@@ -38,6 +38,7 @@ import org.springframework.boot.test.util.EnvironmentTestUtils;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Primary
;
import
org.springframework.test.util.ReflectionTestUtils
;
import
org.springframework.test.util.ReflectionTestUtils
;
import
org.springframework.util.FileCopyUtils
;
import
org.springframework.util.FileCopyUtils
;
...
@@ -254,12 +255,20 @@ public class LiquibaseAutoConfigurationTests {
...
@@ -254,12 +255,20 @@ public class LiquibaseAutoConfigurationTests {
PropertyPlaceholderAutoConfiguration
.
class
);
PropertyPlaceholderAutoConfiguration
.
class
);
this
.
context
.
refresh
();
this
.
context
.
refresh
();
SpringLiquibase
liquibase
=
this
.
context
.
getBean
(
SpringLiquibase
.
class
);
SpringLiquibase
liquibase
=
this
.
context
.
getBean
(
SpringLiquibase
.
class
);
assertThat
(
liquibase
.
getDataSource
()).
isNotNull
();
assertThat
(
liquibase
.
getDataSource
())
.
isEqualTo
(
this
.
context
.
getBean
(
"liquibaseDataSource"
));
}
}
@Configuration
@Configuration
static
class
LiquibaseDataSourceConfiguration
{
static
class
LiquibaseDataSourceConfiguration
{
@Bean
@Primary
public
DataSource
normalDataSource
()
{
return
DataSourceBuilder
.
create
().
url
(
"jdbc:hsqldb:mem:normal"
).
username
(
"sa"
)
.
build
();
}
@LiquibaseDataSource
@LiquibaseDataSource
@Bean
@Bean
public
DataSource
liquibaseDataSource
()
{
public
DataSource
liquibaseDataSource
()
{
...
...
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