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
554bff61
Commit
554bff61
authored
Feb 27, 2019
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.1.x'
parents
7beb6404
38a20f27
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
143 additions
and
1 deletion
+143
-1
FlywayAutoConfiguration.java
...rk/boot/autoconfigure/flyway/FlywayAutoConfiguration.java
+36
-0
NamedParameterJdbcOperationsDependsOnPostProcessor.java
...c/NamedParameterJdbcOperationsDependsOnPostProcessor.java
+40
-0
LiquibaseAutoConfiguration.java
...t/autoconfigure/liquibase/LiquibaseAutoConfiguration.java
+19
-0
JdbcTemplateAutoConfigurationTests.java
...utoconfigure/jdbc/JdbcTemplateAutoConfigurationTests.java
+48
-1
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java
View file @
554bff61
...
...
@@ -46,6 +46,7 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import
org.springframework.boot.autoconfigure.jdbc.DataSourceProperties
;
import
org.springframework.boot.autoconfigure.jdbc.JdbcOperationsDependsOnPostProcessor
;
import
org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration
;
import
org.springframework.boot.autoconfigure.jdbc.NamedParameterJdbcOperationsDependsOnPostProcessor
;
import
org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration
;
import
org.springframework.boot.context.properties.ConfigurationPropertiesBinding
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
...
...
@@ -57,6 +58,7 @@ import org.springframework.core.convert.TypeDescriptor;
import
org.springframework.core.convert.converter.GenericConverter
;
import
org.springframework.core.io.ResourceLoader
;
import
org.springframework.jdbc.core.JdbcOperations
;
import
org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations
;
import
org.springframework.jdbc.support.JdbcUtils
;
import
org.springframework.jdbc.support.MetaDataAccessException
;
import
org.springframework.orm.jpa.AbstractEntityManagerFactoryBean
;
...
...
@@ -76,6 +78,7 @@ import org.springframework.util.StringUtils;
* @author Jacques-Etienne Beaudet
* @author Eddú Meléndez
* @author Dominic Gunn
* @author Dan Zheng
* @since 1.1.0
*/
@SuppressWarnings
(
"deprecation"
)
...
...
@@ -301,6 +304,23 @@ public class FlywayAutoConfiguration {
public
FlywayInitializerJdbcOperationsDependencyConfiguration
()
{
super
(
"flywayInitializer"
);
}
}
/**
* Additional configuration to ensure that {@link NamedParameterJdbcOperations}
* beans depend on the {@code flywayInitializer} bean.
*/
@Configuration
@ConditionalOnClass
(
NamedParameterJdbcOperations
.
class
)
@ConditionalOnBean
(
NamedParameterJdbcOperations
.
class
)
protected
static
class
FlywayInitializerNamedParameterJdbcOperationsDependencyConfiguration
extends
NamedParameterJdbcOperationsDependsOnPostProcessor
{
public
FlywayInitializerNamedParameterJdbcOperationsDependencyConfiguration
()
{
super
(
"flywayInitializer"
);
}
}
...
...
@@ -339,6 +359,22 @@ public class FlywayAutoConfiguration {
}
/**
* Additional configuration to ensure that {@link NamedParameterJdbcOperations} beans
* depend on the {@code flyway} bean.
*/
@Configuration
@ConditionalOnClass
(
NamedParameterJdbcOperations
.
class
)
@ConditionalOnBean
(
NamedParameterJdbcOperations
.
class
)
protected
static
class
FlywayNamedParameterJdbcOperationsDependencyConfiguration
extends
NamedParameterJdbcOperationsDependsOnPostProcessor
{
public
FlywayNamedParameterJdbcOperationsDependencyConfiguration
()
{
super
(
"flyway"
);
}
}
private
static
class
LocationResolver
{
private
static
final
String
VENDOR_PLACEHOLDER
=
"{vendor}"
;
...
...
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/NamedParameterJdbcOperationsDependsOnPostProcessor.java
0 → 100644
View file @
554bff61
/*
* Copyright 2012-2019 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
autoconfigure
.
jdbc
;
import
org.springframework.beans.factory.config.BeanDefinition
;
import
org.springframework.beans.factory.config.BeanFactoryPostProcessor
;
import
org.springframework.boot.autoconfigure.AbstractDependsOnBeanFactoryPostProcessor
;
import
org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations
;
/**
* {@link BeanFactoryPostProcessor} that can be used to dynamically declare that all
* {@link NamedParameterJdbcOperations} beans should "depend on" one or more specific
* beans.
*
* @author Dan Zheng
* @since 2.1.4
* @see BeanDefinition#setDependsOn(String[])
*/
public
class
NamedParameterJdbcOperationsDependsOnPostProcessor
extends
AbstractDependsOnBeanFactoryPostProcessor
{
public
NamedParameterJdbcOperationsDependsOnPostProcessor
(
String
...
dependsOn
)
{
super
(
NamedParameterJdbcOperations
.
class
,
dependsOn
);
}
}
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration.java
View file @
554bff61
...
...
@@ -36,6 +36,7 @@ import org.springframework.boot.autoconfigure.data.jpa.EntityManagerFactoryDepen
import
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
;
import
org.springframework.boot.autoconfigure.jdbc.DataSourceProperties
;
import
org.springframework.boot.autoconfigure.jdbc.JdbcOperationsDependsOnPostProcessor
;
import
org.springframework.boot.autoconfigure.jdbc.NamedParameterJdbcOperationsDependsOnPostProcessor
;
import
org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.boot.jdbc.DataSourceBuilder
;
...
...
@@ -45,6 +46,7 @@ import org.springframework.context.annotation.Import;
import
org.springframework.core.io.Resource
;
import
org.springframework.core.io.ResourceLoader
;
import
org.springframework.jdbc.core.JdbcOperations
;
import
org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations
;
import
org.springframework.orm.jpa.AbstractEntityManagerFactoryBean
;
import
org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean
;
import
org.springframework.util.Assert
;
...
...
@@ -58,6 +60,7 @@ import org.springframework.util.Assert;
* @author Eddú Meléndez
* @author Andy Wilkinson
* @author Dominic Gunn
* @author Dan Zheng
* @since 1.1.0
*/
@Configuration
...
...
@@ -205,4 +208,20 @@ public class LiquibaseAutoConfiguration {
}
/**
* Additional configuration to ensure that {@link NamedParameterJdbcOperations} beans
* depend on the liquibase bean.
*/
@Configuration
@ConditionalOnClass
(
NamedParameterJdbcOperations
.
class
)
@ConditionalOnBean
(
NamedParameterJdbcOperations
.
class
)
protected
static
class
LiquibaseNamedParameterJdbcOperationsDependencyConfiguration
extends
NamedParameterJdbcOperationsDependsOnPostProcessor
{
public
LiquibaseNamedParameterJdbcOperationsDependencyConfiguration
()
{
super
(
"liquibase"
);
}
}
}
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/JdbcTemplateAutoConfigurationTests.java
View file @
554bff61
/*
* Copyright 2012-201
8
the original author or authors.
* Copyright 2012-201
9
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.
...
...
@@ -16,6 +16,8 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
jdbc
;
import
java.util.Collections
;
import
javax.sql.DataSource
;
import
org.junit.Test
;
...
...
@@ -41,6 +43,7 @@ import static org.mockito.Mockito.mock;
* @author Dave Syer
* @author Stephane Nicoll
* @author Kazuki Shimizu
* @author Dan Zheng
*/
public
class
JdbcTemplateAutoConfigurationTests
{
...
...
@@ -185,6 +188,21 @@ public class JdbcTemplateAutoConfigurationTests {
});
}
@Test
public
void
testDependencyToFlywayWithJdbcTemplateMixed
()
{
this
.
contextRunner
.
withUserConfiguration
(
NamedParameterDataSourceMigrationValidator
.
class
)
.
withPropertyValues
(
"spring.flyway.locations:classpath:db/city"
)
.
withConfiguration
(
AutoConfigurations
.
of
(
FlywayAutoConfiguration
.
class
))
.
run
((
context
)
->
{
assertThat
(
context
).
hasNotFailed
();
assertThat
(
context
.
getBean
(
JdbcTemplate
.
class
)).
isNotNull
();
assertThat
(
context
.
getBean
(
NamedParameterDataSourceMigrationValidator
.
class
).
count
)
.
isEqualTo
(
0
);
});
}
@Test
public
void
testDependencyToLiquibase
()
{
this
.
contextRunner
.
withUserConfiguration
(
DataSourceMigrationValidator
.
class
)
...
...
@@ -199,6 +217,23 @@ public class JdbcTemplateAutoConfigurationTests {
});
}
@Test
public
void
testDependencyToLiquibaseWithJdbcTemplateMixed
()
{
this
.
contextRunner
.
withUserConfiguration
(
NamedParameterDataSourceMigrationValidator
.
class
)
.
withPropertyValues
(
"spring.liquibase.changeLog:classpath:db/changelog/db.changelog-city.yaml"
)
.
withConfiguration
(
AutoConfigurations
.
of
(
LiquibaseAutoConfiguration
.
class
))
.
run
((
context
)
->
{
assertThat
(
context
).
hasNotFailed
();
assertThat
(
context
.
getBean
(
JdbcTemplate
.
class
)).
isNotNull
();
assertThat
(
context
.
getBean
(
NamedParameterDataSourceMigrationValidator
.
class
).
count
)
.
isEqualTo
(
0
);
});
}
@Configuration
static
class
CustomConfiguration
{
...
...
@@ -278,4 +313,16 @@ public class JdbcTemplateAutoConfigurationTests {
}
static
class
NamedParameterDataSourceMigrationValidator
{
private
final
Integer
count
;
NamedParameterDataSourceMigrationValidator
(
NamedParameterJdbcTemplate
namedParameterJdbcTemplate
)
{
this
.
count
=
namedParameterJdbcTemplate
.
queryForObject
(
"SELECT COUNT(*) from CITY"
,
Collections
.
emptyMap
(),
Integer
.
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