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
448f1626
Commit
448f1626
authored
Jan 07, 2019
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.1.x'
parents
8136db69
830da28b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
78 additions
and
14 deletions
+78
-14
JpaRepositoriesAutoConfiguration.java
...oconfigure/data/jpa/JpaRepositoriesAutoConfiguration.java
+20
-4
JpaRepositoriesAutoConfigurationTests.java
...igure/data/jpa/JpaRepositoriesAutoConfigurationTests.java
+56
-9
spring-boot-features.adoc
...ing-boot-docs/src/main/asciidoc/spring-boot-features.adoc
+2
-1
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/jpa/JpaRepositoriesAutoConfiguration.java
View file @
448f1626
/*
* 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,9 +16,10 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
data
.
jpa
;
import
java.util.Map
;
import
javax.sql.DataSource
;
import
org.springframework.beans.factory.ObjectProvider
;
import
org.springframework.boot.autoconfigure.AutoConfigureAfter
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.autoconfigure.condition.AnyNestedCondition
;
...
...
@@ -72,8 +73,23 @@ public class JpaRepositoriesAutoConfiguration {
@Bean
@Conditional
(
BootstrapExecutorCondition
.
class
)
public
EntityManagerFactoryBuilderCustomizer
entityManagerFactoryBootstrapExecutorCustomizer
(
ObjectProvider
<
AsyncTaskExecutor
>
taskExecutor
)
{
return
(
builder
)
->
builder
.
setBootstrapExecutor
(
taskExecutor
.
getIfAvailable
());
Map
<
String
,
AsyncTaskExecutor
>
taskExecutors
)
{
return
(
builder
)
->
{
AsyncTaskExecutor
bootstrapExecutor
=
determineBootstrapExecutor
(
taskExecutors
);
if
(
bootstrapExecutor
!=
null
)
{
builder
.
setBootstrapExecutor
(
bootstrapExecutor
);
}
};
}
private
AsyncTaskExecutor
determineBootstrapExecutor
(
Map
<
String
,
AsyncTaskExecutor
>
taskExecutors
)
{
if
(
taskExecutors
.
size
()
==
1
)
{
return
taskExecutors
.
values
().
iterator
().
next
();
}
return
taskExecutors
.
get
(
TaskExecutionAutoConfiguration
.
APPLICATION_TASK_EXECUTOR_BEAN_NAME
);
}
private
static
final
class
BootstrapExecutorCondition
extends
AnyNestedCondition
{
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/jpa/JpaRepositoriesAutoConfigurationTests.java
View file @
448f1626
/*
* 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.
...
...
@@ -31,12 +31,17 @@ import org.springframework.boot.autoconfigure.data.jpa.city.CityRepository;
import
org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration
;
import
org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration
;
import
org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration
;
import
org.springframework.boot.autoconfigure.task.TaskSchedulingAutoConfiguration
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.ComponentScan.Filter
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.FilterType
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.core.task.SimpleAsyncTaskExecutor
;
import
org.springframework.data.jpa.repository.config.EnableJpaRepositories
;
import
org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean
;
import
org.springframework.scheduling.annotation.EnableScheduling
;
import
org.springframework.transaction.PlatformTransactionManager
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
...
...
@@ -52,8 +57,7 @@ public class JpaRepositoriesAutoConfigurationTests {
private
final
ApplicationContextRunner
contextRunner
=
new
ApplicationContextRunner
()
.
withConfiguration
(
AutoConfigurations
.
of
(
HibernateJpaAutoConfiguration
.
class
,
JpaRepositoriesAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
,
TaskExecutionAutoConfiguration
.
class
))
PropertyPlaceholderAutoConfiguration
.
class
))
.
withUserConfiguration
(
EmbeddedDataSourceConfiguration
.
class
);
@Test
...
...
@@ -87,33 +91,76 @@ public class JpaRepositoriesAutoConfigurationTests {
}
@Test
public
void
whenBootstrappingModeIsLazyBootstrapExecutorIsConfigured
()
{
this
.
contextRunner
.
withUserConfiguration
(
TestConfiguration
.
class
)
public
void
whenBootstrappingModeIsLazyWithMultipleAsyncExecutorBootstrapExecutorIsConfigured
()
{
this
.
contextRunner
.
withUserConfiguration
(
MultipleAsyncTaskExecutorConfiguration
.
class
)
.
withConfiguration
(
AutoConfigurations
.
of
(
TaskExecutionAutoConfiguration
.
class
,
TaskSchedulingAutoConfiguration
.
class
))
.
withPropertyValues
(
"spring.data.jpa.repositories.bootstrap-mode=lazy"
)
.
run
((
context
)
->
assertThat
(
context
.
getBean
(
LocalContainerEntityManagerFactoryBean
.
class
)
.
getBootstrapExecutor
()).
isNotNull
());
.
getBootstrapExecutor
()).
isEqualTo
(
context
.
getBean
(
"applicationTaskExecutor"
)));
}
@Test
public
void
whenBootstrappingModeIsLazyWithSingleAsyncExecutorBootstrapExecutorIsConfigured
()
{
this
.
contextRunner
.
withUserConfiguration
(
SingleAsyncTaskExecutorConfiguration
.
class
)
.
withPropertyValues
(
"spring.data.jpa.repositories.bootstrap-mode=lazy"
)
.
run
((
context
)
->
assertThat
(
context
.
getBean
(
LocalContainerEntityManagerFactoryBean
.
class
)
.
getBootstrapExecutor
()).
isEqualTo
(
context
.
getBean
(
"testAsyncTaskExecutor"
)));
}
@Test
public
void
whenBootstrappingModeIsDeferredBootstrapExecutorIsConfigured
()
{
this
.
contextRunner
.
withUserConfiguration
(
TestConfiguration
.
class
)
this
.
contextRunner
.
withUserConfiguration
(
MultipleAsyncTaskExecutorConfiguration
.
class
)
.
withConfiguration
(
AutoConfigurations
.
of
(
TaskExecutionAutoConfiguration
.
class
,
TaskSchedulingAutoConfiguration
.
class
))
.
withPropertyValues
(
"spring.data.jpa.repositories.bootstrap-mode=deferred"
)
.
run
((
context
)
->
assertThat
(
context
.
getBean
(
LocalContainerEntityManagerFactoryBean
.
class
)
.
getBootstrapExecutor
()).
isNotNull
());
.
getBootstrapExecutor
()).
isEqualTo
(
context
.
getBean
(
"applicationTaskExecutor"
)));
}
@Test
public
void
whenBootstrappingModeIsDefaultBootstrapExecutorIsNotConfigured
()
{
this
.
contextRunner
.
withUserConfiguration
(
TestConfiguration
.
class
)
this
.
contextRunner
.
withUserConfiguration
(
MultipleAsyncTaskExecutorConfiguration
.
class
)
.
withConfiguration
(
AutoConfigurations
.
of
(
TaskExecutionAutoConfiguration
.
class
,
TaskSchedulingAutoConfiguration
.
class
))
.
withPropertyValues
(
"spring.data.jpa.repositories.bootstrap-mode=default"
)
.
run
((
context
)
->
assertThat
(
context
.
getBean
(
LocalContainerEntityManagerFactoryBean
.
class
)
.
getBootstrapExecutor
()).
isNull
());
}
@Configuration
@EnableScheduling
@Import
(
TestConfiguration
.
class
)
protected
static
class
MultipleAsyncTaskExecutorConfiguration
{
}
@Configuration
@Import
(
TestConfiguration
.
class
)
protected
static
class
SingleAsyncTaskExecutorConfiguration
{
@Bean
public
SimpleAsyncTaskExecutor
testAsyncTaskExecutor
()
{
return
new
SimpleAsyncTaskExecutor
();
}
}
@Configuration
@TestAutoConfigurationPackage
(
City
.
class
)
protected
static
class
TestConfiguration
{
...
...
spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc
View file @
448f1626
...
...
@@ -3841,7 +3841,8 @@ Spring Data JPA repositories support three different modes of bootstrapping: def
deferred, and lazy. To enable deferred or lazy bootstrapping, set the
`spring.data.jpa.repositories.bootstrap-mode` to `deferred` or `lazy` respectively. When
using deferred or lazy bootstrapping, the auto-configured `EntityManagerFactoryBuilder`
will use the context's async task executor, if any, as the bootstrap executor.
will use the context's `AsyncTaskExecutor`, if any, as the bootstrap executor. If more
than one exists, the one named `applicationTaskExecutor` will be used.
TIP: We have barely scratched the surface of Spring Data JPA. For complete details, see
the https://docs.spring.io/spring-data/jpa/docs/current/reference/html/[Spring Data JPA
...
...
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