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
eebd906c
Commit
eebd906c
authored
Feb 27, 2019
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish contribution
Closes gh-16047
parent
2c4afb3b
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
11 additions
and
197 deletions
+11
-197
FlywayAutoConfiguration.java
...rk/boot/autoconfigure/flyway/FlywayAutoConfiguration.java
+1
-1
NamedParameterJdbcOperationsDependsOnPostProcessor.java
...c/NamedParameterJdbcOperationsDependsOnPostProcessor.java
+1
-1
LiquibaseAutoConfiguration.java
...t/autoconfigure/liquibase/LiquibaseAutoConfiguration.java
+1
-1
JdbcTemplateAutoConfigurationTests.java
...utoconfigure/jdbc/JdbcTemplateAutoConfigurationTests.java
+8
-129
db.changelog-city-np.yaml
...src/test/resources/db/changelog/db.changelog-city-np.yaml
+0
-55
V1__init.sql
...-autoconfigure/src/test/resources/db/city_np/V1__init.sql
+0
-9
V2__add_data.sql
...oconfigure/src/test/resources/db/city_np/V2__add_data.sql
+0
-1
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java
View file @
eebd906c
/*
/*
* 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");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
...
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/NamedParameterJdbcOperationsDependsOnPostProcessor.java
View file @
eebd906c
...
@@ -27,7 +27,7 @@ import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
...
@@ -27,7 +27,7 @@ import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
* beans.
* beans.
*
*
* @author Dan Zheng
* @author Dan Zheng
* @since 2.1.
x
* @since 2.1.
4
* @see BeanDefinition#setDependsOn(String[])
* @see BeanDefinition#setDependsOn(String[])
*/
*/
public
class
NamedParameterJdbcOperationsDependsOnPostProcessor
public
class
NamedParameterJdbcOperationsDependsOnPostProcessor
...
...
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration.java
View file @
eebd906c
/*
/*
* 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");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/JdbcTemplateAutoConfigurationTests.java
View file @
eebd906c
/*
/*
* 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");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -16,27 +16,15 @@
...
@@ -16,27 +16,15 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
jdbc
;
package
org
.
springframework
.
boot
.
autoconfigure
.
jdbc
;
import
java.util.HashMap
;
import
java.util.Collections
;
import
java.util.Map
;
import
javax.sql.DataSource
;
import
javax.sql.DataSource
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.springframework.beans.BeansException
;
import
org.springframework.beans.factory.NoSuchBeanDefinitionException
;
import
org.springframework.beans.factory.config.BeanDefinition
;
import
org.springframework.beans.factory.config.ConfigurableListableBeanFactory
;
import
org.springframework.beans.factory.support.BeanDefinitionRegistry
;
import
org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor
;
import
org.springframework.boot.autoconfigure.AutoConfigurations
;
import
org.springframework.boot.autoconfigure.AutoConfigurations
;
import
org.springframework.boot.autoconfigure.AutoConfigureAfter
;
import
org.springframework.boot.autoconfigure.AutoConfigureBefore
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate
;
import
org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration
;
import
org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration
;
import
org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration
;
import
org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
...
@@ -47,7 +35,6 @@ import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
...
@@ -47,7 +35,6 @@ import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
import
org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate
;
import
org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
junit
.
Assert
.
fail
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
mock
;
/**
/**
...
@@ -205,45 +192,14 @@ public class JdbcTemplateAutoConfigurationTests {
...
@@ -205,45 +192,14 @@ public class JdbcTemplateAutoConfigurationTests {
public
void
testDependencyToFlywayWithJdbcTemplateMixed
()
{
public
void
testDependencyToFlywayWithJdbcTemplateMixed
()
{
this
.
contextRunner
this
.
contextRunner
.
withUserConfiguration
(
NamedParameterDataSourceMigrationValidator
.
class
)
.
withUserConfiguration
(
NamedParameterDataSourceMigrationValidator
.
class
)
.
withPropertyValues
(
"spring.flyway.locations:classpath:db/city
_np
"
)
.
withPropertyValues
(
"spring.flyway.locations:classpath:db/city"
)
.
withConfiguration
(
AutoConfigurations
.
of
(
FlywayAutoConfiguration
.
class
))
.
withConfiguration
(
AutoConfigurations
.
of
(
FlywayAutoConfiguration
.
class
))
.
run
((
context
)
->
{
.
run
((
context
)
->
{
assertThat
(
context
).
hasNotFailed
();
assertThat
(
context
).
hasNotFailed
();
assertThat
(
context
.
getBean
(
JdbcTemplate
.
class
)).
isNotNull
();
assertThat
(
context
.
getBean
(
JdbcTemplate
.
class
)).
isNotNull
();
assertThat
(
context
.
getBean
(
assertThat
(
context
.
getBean
(
NamedParameterDataSourceMigrationValidator
.
class
).
count
)
NamedParameterDataSourceMigrationValidator
.
class
).
count
)
.
isEqualTo
(
1
);
.
isEqualTo
(
0
);
});
}
@Test
public
void
testDependencyToFlywayWithOnlyNamedParameterJdbcTemplate
()
{
ApplicationContextRunner
contextRunner1
=
new
ApplicationContextRunner
()
.
withPropertyValues
(
"spring.datasource.initialization-mode=never"
,
"spring.datasource.generate-unique-name=true"
)
.
withConfiguration
(
AutoConfigurations
.
of
(
DataSourceAutoConfiguration
.
class
,
JdbcTemplateAutoConfiguration
.
class
,
OnlyNamedParameterJdbcTemplateAutoConfiguration
.
class
));
contextRunner1
.
withUserConfiguration
(
NamedParameterDataSourceMigrationValidator
.
class
)
.
withPropertyValues
(
"spring.flyway.locations:classpath:db/city_np"
)
.
withConfiguration
(
AutoConfigurations
.
of
(
FlywayAutoConfiguration
.
class
))
.
run
((
context
)
->
{
assertThat
(
context
).
hasNotFailed
();
assertThat
(
context
.
containsBean
(
"jdbcTemplate"
)).
isFalse
();
try
{
JdbcTemplate
jdbcTemplate
=
context
.
getBean
(
JdbcTemplate
.
class
);
fail
(
"org.springframework.boot.autoconfigure.jdbc.JdcTemplate should not exist in the application context"
);
}
catch
(
NoSuchBeanDefinitionException
ex
)
{
}
assertThat
(
context
.
getBean
(
NamedParameterJdbcTemplate
.
class
))
.
isNotNull
();
assertThat
(
context
.
getBean
(
NamedParameterDataSourceMigrationValidator
.
class
).
count
)
.
isEqualTo
(
1
);
});
});
}
}
...
@@ -266,7 +222,7 @@ public class JdbcTemplateAutoConfigurationTests {
...
@@ -266,7 +222,7 @@ public class JdbcTemplateAutoConfigurationTests {
this
.
contextRunner
this
.
contextRunner
.
withUserConfiguration
(
NamedParameterDataSourceMigrationValidator
.
class
)
.
withUserConfiguration
(
NamedParameterDataSourceMigrationValidator
.
class
)
.
withPropertyValues
(
.
withPropertyValues
(
"spring.liquibase.changeLog:classpath:db/changelog/db.changelog-city
-np
.yaml"
)
"spring.liquibase.changeLog:classpath:db/changelog/db.changelog-city.yaml"
)
.
withConfiguration
(
.
withConfiguration
(
AutoConfigurations
.
of
(
LiquibaseAutoConfiguration
.
class
))
AutoConfigurations
.
of
(
LiquibaseAutoConfiguration
.
class
))
.
run
((
context
)
->
{
.
run
((
context
)
->
{
...
@@ -274,34 +230,7 @@ public class JdbcTemplateAutoConfigurationTests {
...
@@ -274,34 +230,7 @@ public class JdbcTemplateAutoConfigurationTests {
assertThat
(
context
.
getBean
(
JdbcTemplate
.
class
)).
isNotNull
();
assertThat
(
context
.
getBean
(
JdbcTemplate
.
class
)).
isNotNull
();
assertThat
(
context
.
getBean
(
assertThat
(
context
.
getBean
(
NamedParameterDataSourceMigrationValidator
.
class
).
count
)
NamedParameterDataSourceMigrationValidator
.
class
).
count
)
.
isEqualTo
(
1
);
.
isEqualTo
(
0
);
});
}
@Test
public
void
testDependencyToLiquibaseWithOnlyNamedParameterJdbcTemplate
()
{
this
.
contextRunner
.
withUserConfiguration
(
NamedParameterDataSourceMigrationValidator
.
class
)
.
withPropertyValues
(
"spring.liquibase.changeLog:classpath:db/changelog/db.changelog-city-np.yaml"
)
.
withConfiguration
(
AutoConfigurations
.
of
(
OnlyNamedParameterJdbcTemplateAutoConfiguration
.
class
,
LiquibaseAutoConfiguration
.
class
))
.
run
((
context
)
->
{
assertThat
(
context
).
hasNotFailed
();
assertThat
(
context
.
containsBean
(
"jdbcTemplate"
)).
isFalse
();
try
{
JdbcTemplate
jdbcTemplate
=
context
.
getBean
(
JdbcTemplate
.
class
);
fail
(
"org.springframework.boot.autoconfigure.jdbc.JdcTemplate should not exist in the application context"
);
}
catch
(
NoSuchBeanDefinitionException
ex
)
{
}
assertThat
(
context
.
getBean
(
NamedParameterJdbcTemplate
.
class
))
.
isNotNull
();
assertThat
(
context
.
getBean
(
NamedParameterDataSourceMigrationValidator
.
class
).
count
)
.
isEqualTo
(
1
);
});
});
}
}
...
@@ -390,58 +319,8 @@ public class JdbcTemplateAutoConfigurationTests {
...
@@ -390,58 +319,8 @@ public class JdbcTemplateAutoConfigurationTests {
NamedParameterDataSourceMigrationValidator
(
NamedParameterDataSourceMigrationValidator
(
NamedParameterJdbcTemplate
namedParameterJdbcTemplate
)
{
NamedParameterJdbcTemplate
namedParameterJdbcTemplate
)
{
String
sql
=
"SELECT COUNT(*) from CITY WHERE id = :id"
;
this
.
count
=
namedParameterJdbcTemplate
.
queryForObject
(
Map
<
String
,
Long
>
param
=
new
HashMap
<>();
"SELECT COUNT(*) from CITY"
,
Collections
.
emptyMap
(),
Integer
.
class
);
param
.
put
(
"id"
,
1L
);
this
.
count
=
namedParameterJdbcTemplate
.
queryForObject
(
sql
,
param
,
Integer
.
class
);
}
}
@Configuration
@ConditionalOnClass
({
DataSource
.
class
})
@ConditionalOnSingleCandidate
(
DataSource
.
class
)
@AutoConfigureAfter
({
DataSourceAutoConfiguration
.
class
,
JdbcTemplateAutoConfiguration
.
class
})
@AutoConfigureBefore
({
FlywayAutoConfiguration
.
class
,
LiquibaseAutoConfiguration
.
class
})
@EnableConfigurationProperties
(
JdbcProperties
.
class
)
static
class
OnlyNamedParameterJdbcTemplateAutoConfiguration
implements
BeanDefinitionRegistryPostProcessor
{
@Bean
public
NamedParameterJdbcTemplate
myNamedParameterJdbcTemplate
(
DataSource
dataSource
)
{
return
new
NamedParameterJdbcTemplate
(
dataSource
);
}
@Override
public
void
postProcessBeanFactory
(
ConfigurableListableBeanFactory
beanFactory
)
throws
BeansException
{
// do nothing
}
/**
* <p>
* we should remove the jdbc template bean definition to keep only
* NamedParameterJdbcTemplate is registerd in the bean container
* </p>
* @param registry the bean definition registry.
* @throws BeansException if the bean registry have any exception.
*/
@Override
public
void
postProcessBeanDefinitionRegistry
(
BeanDefinitionRegistry
registry
)
throws
BeansException
{
String
[]
excludeBeanNames
=
new
String
[]
{
"jdbcTemplate"
,
"namedParameterJdbcTemplate"
};
for
(
String
beanName
:
excludeBeanNames
)
{
BeanDefinition
beanDefinition
=
registry
.
getBeanDefinition
(
beanName
);
if
(
beanDefinition
!=
null
)
{
registry
.
removeBeanDefinition
(
beanName
);
}
}
}
}
}
}
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/resources/db/changelog/db.changelog-city-np.yaml
deleted
100644 → 0
View file @
2c4afb3b
databaseChangeLog
:
-
changeSet
:
id
:
1
author
:
dan-zheng
changes
:
-
createSequence
:
sequenceName
:
hibernate_sequence
-
createTable
:
tableName
:
city
columns
:
-
column
:
name
:
id
type
:
bigint
autoIncrement
:
true
constraints
:
primaryKey
:
true
nullable
:
false
-
column
:
name
:
name
type
:
varchar(50)
constraints
:
nullable
:
false
-
column
:
name
:
state
type
:
varchar(50)
constraints
:
nullable
:
false
-
column
:
name
:
country
type
:
varchar(50)
constraints
:
nullable
:
false
-
column
:
name
:
map
type
:
varchar(50)
constraints
:
nullable
:
true
-
insert
:
tableName
:
city
columns
:
-
column
:
name
:
id
value
:
1
-
column
:
name
:
name
value
:
Hangzhou
-
column
:
name
:
state
value
:
Zhejiang
-
column
:
name
:
country
value
:
China
-
column
:
name
:
map
value
:
map
spring-boot-project/spring-boot-autoconfigure/src/test/resources/db/city_np/V1__init.sql
deleted
100644 → 0
View file @
2c4afb3b
CREATE
SEQUENCE
HIBERNATE_SEQUENCE
;
CREATE
TABLE
CITY
(
id
BIGINT
GENERATED
BY
DEFAULT
AS
IDENTITY
,
name
VARCHAR
(
30
),
state
VARCHAR
(
30
),
country
VARCHAR
(
30
),
map
VARCHAR
(
30
)
);
spring-boot-project/spring-boot-autoconfigure/src/test/resources/db/city_np/V2__add_data.sql
deleted
100644 → 0
View file @
2c4afb3b
INSERT
INTO
CITY
(
id
,
name
,
state
,
country
,
map
)
VALUES
(
1
,
'Hangzhou'
,
'Zhejiang'
,
'China'
,
'map'
);
\ No newline at end of file
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