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
2db8e7ee
Commit
2db8e7ee
authored
Oct 29, 2020
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish "Add liquibase driver class name property"
See gh-23958
parent
8a9b31aa
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
7 deletions
+29
-7
LiquibaseAutoConfiguration.java
...t/autoconfigure/liquibase/LiquibaseAutoConfiguration.java
+13
-6
LiquibaseAutoConfigurationTests.java
...oconfigure/liquibase/LiquibaseAutoConfigurationTests.java
+15
-0
howto.adoc
...oot-project/spring-boot-docs/src/docs/asciidoc/howto.adoc
+1
-1
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration.java
View file @
2db8e7ee
...
...
@@ -54,6 +54,7 @@ import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
import
org.springframework.jdbc.datasource.SimpleDriverDataSource
;
import
org.springframework.orm.jpa.AbstractEntityManagerFactoryBean
;
import
org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean
;
import
org.springframework.util.StringUtils
;
/**
* {@link EnableAutoConfiguration Auto-configuration} for Liquibase.
...
...
@@ -148,8 +149,19 @@ public class LiquibaseAutoConfiguration {
String
url
=
getProperty
(
this
.
properties
::
getUrl
,
dataSourceProperties:
:
determineUrl
);
String
user
=
getProperty
(
this
.
properties
::
getUser
,
dataSourceProperties:
:
determineUsername
);
String
password
=
getProperty
(
this
.
properties
::
getPassword
,
dataSourceProperties:
:
determinePassword
);
String
driverClassName
=
determineDriverClassName
(
dataSourceProperties
,
url
);
return
DataSourceBuilder
.
create
().
type
(
determineDataSourceType
()).
url
(
url
).
username
(
user
).
password
(
password
)
.
driverClassName
(
determineDriverClassName
(
url
)).
build
();
.
driverClassName
(
driverClassName
).
build
();
}
private
String
determineDriverClassName
(
DataSourceProperties
dataSourceProperties
,
String
url
)
{
if
(
StringUtils
.
hasText
(
this
.
properties
.
getDriverClassName
()))
{
return
this
.
properties
.
getDriverClassName
();
}
if
(
StringUtils
.
hasText
(
dataSourceProperties
.
getDriverClassName
()))
{
return
dataSourceProperties
.
getDriverClassName
();
}
return
StringUtils
.
hasText
(
url
)
?
DatabaseDriver
.
fromJdbcUrl
(
url
).
getDriverClassName
()
:
null
;
}
private
Class
<?
extends
DataSource
>
determineDataSourceType
()
{
...
...
@@ -157,11 +169,6 @@ public class LiquibaseAutoConfiguration {
return
(
type
!=
null
)
?
type
:
SimpleDriverDataSource
.
class
;
}
private
String
determineDriverClassName
(
String
url
)
{
String
driverClassName
=
this
.
properties
.
getDriverClassName
();
return
(
driverClassName
!=
null
)
?
driverClassName
:
DatabaseDriver
.
fromJdbcUrl
(
url
).
getDriverClassName
();
}
private
String
getProperty
(
Supplier
<
String
>
property
,
Supplier
<
String
>
defaultValue
)
{
String
value
=
property
.
get
();
return
(
value
!=
null
)
?
value
:
defaultValue
.
get
();
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfigurationTests.java
View file @
2db8e7ee
...
...
@@ -243,6 +243,21 @@ class LiquibaseAutoConfigurationTests {
}));
}
@Test
void
overrideDataSourceWithFallbackDriverClassName
()
{
String
jdbcUrl
=
"jdbc:hsqldb:mem:liquibase"
;
String
driverClassName
=
"org.hsqldb.jdbcDriver"
;
this
.
contextRunner
.
withUserConfiguration
(
EmbeddedDataSourceConfiguration
.
class
)
.
withPropertyValues
(
"spring.liquibase.url:"
+
jdbcUrl
,
"spring.datasource.driver-class-name:"
+
driverClassName
)
.
run
(
assertLiquibase
((
liquibase
)
->
{
DataSource
dataSource
=
liquibase
.
getDataSource
();
assertThat
(((
HikariDataSource
)
dataSource
).
isClosed
()).
isTrue
();
assertThat
(((
HikariDataSource
)
dataSource
).
getJdbcUrl
()).
isEqualTo
(
jdbcUrl
);
assertThat
(((
HikariDataSource
)
dataSource
).
getDriverClassName
()).
isEqualTo
(
driverClassName
);
}));
}
@Test
void
overrideUser
()
{
String
jdbcUrl
=
"jdbc:hsqldb:mem:normal"
;
...
...
spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto.adoc
View file @
2db8e7ee
...
...
@@ -2217,7 +2217,7 @@ In addition to YAML, Liquibase also supports JSON, XML, and SQL change log forma
By default, Liquibase autowires the (`@Primary`) `DataSource` in your context and uses that for migrations.
If you need to use a different `DataSource`, you can create one and mark its `@Bean` as `@LiquibaseDataSource`.
If you do so and you want two data sources, remember to create another one and mark it as `@Primary`.
Alternatively, you can use Liquibase's native `DataSource` by setting `spring.liquibase.[url,user,password]` in external properties.
Alternatively, you can use Liquibase's native `DataSource` by setting `spring.liquibase.[
driver-class-name,
url,user,password]` in external properties.
Setting either `spring.liquibase.url` or `spring.liquibase.user` is sufficient to cause Liquibase to use its own `DataSource`.
If any of the three properties has not been set, the value of its equivalent `spring.datasource` property will be used.
...
...
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