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
439344fd
Commit
439344fd
authored
Jan 26, 2021
by
Phillip Webb
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.4.x'
Closes gh-24996
parents
b1f27b76
1def245a
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
80 additions
and
7 deletions
+80
-7
ConfigDataLoader.java
...springframework/boot/context/config/ConfigDataLoader.java
+4
-2
ConfigDataLoaders.java
...pringframework/boot/context/config/ConfigDataLoaders.java
+2
-1
ConfigDataLocationResolver.java
...ework/boot/context/config/ConfigDataLocationResolver.java
+4
-2
ConfigDataLocationResolvers.java
...work/boot/context/config/ConfigDataLocationResolvers.java
+1
-0
ConfigDataLoadersTests.java
...framework/boot/context/config/ConfigDataLoadersTests.java
+35
-1
ConfigDataLocationResolversTests.java
...boot/context/config/ConfigDataLocationResolversTests.java
+34
-1
No files found.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataLoader.java
View file @
439344fd
/*
/*
* Copyright 2012-202
0
the original author or authors.
* Copyright 2012-202
1
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.
...
@@ -23,6 +23,7 @@ import org.apache.commons.logging.Log;
...
@@ -23,6 +23,7 @@ import org.apache.commons.logging.Log;
import
org.springframework.boot.BootstrapContext
;
import
org.springframework.boot.BootstrapContext
;
import
org.springframework.boot.BootstrapRegistry
;
import
org.springframework.boot.BootstrapRegistry
;
import
org.springframework.boot.ConfigurableBootstrapContext
;
import
org.springframework.boot.ConfigurableBootstrapContext
;
import
org.springframework.boot.logging.DeferredLogFactory
;
/**
/**
* Strategy class that can be used used to load {@link ConfigData} for a given
* Strategy class that can be used used to load {@link ConfigData} for a given
...
@@ -30,7 +31,8 @@ import org.springframework.boot.ConfigurableBootstrapContext;
...
@@ -30,7 +31,8 @@ import org.springframework.boot.ConfigurableBootstrapContext;
* {@code spring.factories} entries. The following constructor parameter types are
* {@code spring.factories} entries. The following constructor parameter types are
* supported:
* supported:
* <ul>
* <ul>
* <li>{@link Log} - if the resolver needs deferred logging</li>
* <li>{@link Log} or {@link DeferredLogFactory} - if the loader needs deferred
* logging</li>
* <li>{@link ConfigurableBootstrapContext} - A bootstrap context that can be used to
* <li>{@link ConfigurableBootstrapContext} - A bootstrap context that can be used to
* store objects that may be expensive to create, or need to be shared
* store objects that may be expensive to create, or need to be shared
* ({@link BootstrapContext} or {@link BootstrapRegistry} may also be used).</li>
* ({@link BootstrapContext} or {@link BootstrapRegistry} may also be used).</li>
...
...
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataLoaders.java
View file @
439344fd
/*
/*
* Copyright 2012-202
0
the original author or authors.
* Copyright 2012-202
1
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.
...
@@ -68,6 +68,7 @@ class ConfigDataLoaders {
...
@@ -68,6 +68,7 @@ class ConfigDataLoaders {
Instantiator
<
ConfigDataLoader
<?>>
instantiator
=
new
Instantiator
<>(
ConfigDataLoader
.
class
,
Instantiator
<
ConfigDataLoader
<?>>
instantiator
=
new
Instantiator
<>(
ConfigDataLoader
.
class
,
(
availableParameters
)
->
{
(
availableParameters
)
->
{
availableParameters
.
add
(
Log
.
class
,
logFactory:
:
getLog
);
availableParameters
.
add
(
Log
.
class
,
logFactory:
:
getLog
);
availableParameters
.
add
(
DeferredLogFactory
.
class
,
logFactory
);
availableParameters
.
add
(
ConfigurableBootstrapContext
.
class
,
bootstrapContext
);
availableParameters
.
add
(
ConfigurableBootstrapContext
.
class
,
bootstrapContext
);
availableParameters
.
add
(
BootstrapContext
.
class
,
bootstrapContext
);
availableParameters
.
add
(
BootstrapContext
.
class
,
bootstrapContext
);
availableParameters
.
add
(
BootstrapRegistry
.
class
,
bootstrapContext
);
availableParameters
.
add
(
BootstrapRegistry
.
class
,
bootstrapContext
);
...
...
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataLocationResolver.java
View file @
439344fd
/*
/*
* Copyright 2012-202
0
the original author or authors.
* Copyright 2012-202
1
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.
...
@@ -25,6 +25,7 @@ import org.springframework.boot.BootstrapContext;
...
@@ -25,6 +25,7 @@ import org.springframework.boot.BootstrapContext;
import
org.springframework.boot.BootstrapRegistry
;
import
org.springframework.boot.BootstrapRegistry
;
import
org.springframework.boot.ConfigurableBootstrapContext
;
import
org.springframework.boot.ConfigurableBootstrapContext
;
import
org.springframework.boot.context.properties.bind.Binder
;
import
org.springframework.boot.context.properties.bind.Binder
;
import
org.springframework.boot.logging.DeferredLogFactory
;
import
org.springframework.core.Ordered
;
import
org.springframework.core.Ordered
;
import
org.springframework.core.annotation.Order
;
import
org.springframework.core.annotation.Order
;
import
org.springframework.core.env.Environment
;
import
org.springframework.core.env.Environment
;
...
@@ -36,7 +37,8 @@ import org.springframework.core.io.ResourceLoader;
...
@@ -36,7 +37,8 @@ import org.springframework.core.io.ResourceLoader;
* {@code spring.factories} entries. The following constructor parameter types are
* {@code spring.factories} entries. The following constructor parameter types are
* supported:
* supported:
* <ul>
* <ul>
* <li>{@link Log} - if the resolver needs deferred logging</li>
* <li>{@link Log} or {@link DeferredLogFactory} - if the resolver needs deferred
* logging</li>
* <li>{@link Binder} - if the resolver needs to obtain values from the initial
* <li>{@link Binder} - if the resolver needs to obtain values from the initial
* {@link Environment}</li>
* {@link Environment}</li>
* <li>{@link ResourceLoader} - if the resolver needs a resource loader</li>
* <li>{@link ResourceLoader} - if the resolver needs a resource loader</li>
...
...
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataLocationResolvers.java
View file @
439344fd
...
@@ -70,6 +70,7 @@ class ConfigDataLocationResolvers {
...
@@ -70,6 +70,7 @@ class ConfigDataLocationResolvers {
Instantiator
<
ConfigDataLocationResolver
<?>>
instantiator
=
new
Instantiator
<>(
ConfigDataLocationResolver
.
class
,
Instantiator
<
ConfigDataLocationResolver
<?>>
instantiator
=
new
Instantiator
<>(
ConfigDataLocationResolver
.
class
,
(
availableParameters
)
->
{
(
availableParameters
)
->
{
availableParameters
.
add
(
Log
.
class
,
logFactory:
:
getLog
);
availableParameters
.
add
(
Log
.
class
,
logFactory:
:
getLog
);
availableParameters
.
add
(
DeferredLogFactory
.
class
,
logFactory
);
availableParameters
.
add
(
Binder
.
class
,
binder
);
availableParameters
.
add
(
Binder
.
class
,
binder
);
availableParameters
.
add
(
ResourceLoader
.
class
,
resourceLoader
);
availableParameters
.
add
(
ResourceLoader
.
class
,
resourceLoader
);
availableParameters
.
add
(
ConfigurableBootstrapContext
.
class
,
bootstrapContext
);
availableParameters
.
add
(
ConfigurableBootstrapContext
.
class
,
bootstrapContext
);
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataLoadersTests.java
View file @
439344fd
/*
/*
* Copyright 2012-202
0
the original author or authors.
* Copyright 2012-202
1
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.
...
@@ -57,6 +57,20 @@ class ConfigDataLoadersTests {
...
@@ -57,6 +57,20 @@ class ConfigDataLoadersTests {
Arrays
.
asList
(
LoggingConfigDataLoader
.
class
.
getName
()));
Arrays
.
asList
(
LoggingConfigDataLoader
.
class
.
getName
()));
}
}
@Test
void
createWhenLoaderHasDeferredLogFactoryParameterInjectsDeferredLogFactory
()
{
ConfigDataLoaders
loaders
=
new
ConfigDataLoaders
(
this
.
logFactory
,
this
.
bootstrapContext
,
Arrays
.
asList
(
DeferredLogFactoryConfigDataLoader
.
class
.
getName
()));
assertThat
(
loaders
).
extracting
(
"loaders"
).
asList
()
.
satisfies
(
this
::
containsValidDeferredLogFactoryConfigDataLoader
);
}
private
void
containsValidDeferredLogFactoryConfigDataLoader
(
List
<?>
list
)
{
assertThat
(
list
).
hasSize
(
1
);
DeferredLogFactoryConfigDataLoader
loader
=
(
DeferredLogFactoryConfigDataLoader
)
list
.
get
(
0
);
assertThat
(
loader
.
getLogFactory
()).
isSameAs
(
this
.
logFactory
);
}
@Test
@Test
void
createWhenLoaderHasBootstrapParametersInjectsBootstrapContext
()
{
void
createWhenLoaderHasBootstrapParametersInjectsBootstrapContext
()
{
new
ConfigDataLoaders
(
this
.
logFactory
,
this
.
bootstrapContext
,
new
ConfigDataLoaders
(
this
.
logFactory
,
this
.
bootstrapContext
,
...
@@ -144,6 +158,26 @@ class ConfigDataLoadersTests {
...
@@ -144,6 +158,26 @@ class ConfigDataLoadersTests {
}
}
static
class
DeferredLogFactoryConfigDataLoader
implements
ConfigDataLoader
<
ConfigDataResource
>
{
private
final
DeferredLogFactory
logFactory
;
DeferredLogFactoryConfigDataLoader
(
DeferredLogFactory
logFactory
)
{
assertThat
(
logFactory
).
isNotNull
();
this
.
logFactory
=
logFactory
;
}
@Override
public
ConfigData
load
(
ConfigDataLoaderContext
context
,
ConfigDataResource
resource
)
throws
IOException
{
throw
new
AssertionError
(
"Unexpected call"
);
}
DeferredLogFactory
getLogFactory
()
{
return
this
.
logFactory
;
}
}
static
class
BootstrappingConfigDataLoader
implements
ConfigDataLoader
<
ConfigDataResource
>
{
static
class
BootstrappingConfigDataLoader
implements
ConfigDataLoader
<
ConfigDataResource
>
{
BootstrappingConfigDataLoader
(
ConfigurableBootstrapContext
configurableBootstrapContext
,
BootstrappingConfigDataLoader
(
ConfigurableBootstrapContext
configurableBootstrapContext
,
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataLocationResolversTests.java
View file @
439344fd
/*
/*
* Copyright 2012-202
0
the original author or authors.
* Copyright 2012-202
1
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.
...
@@ -23,6 +23,7 @@ import java.util.Collections;
...
@@ -23,6 +23,7 @@ import java.util.Collections;
import
java.util.List
;
import
java.util.List
;
import
java.util.function.Supplier
;
import
java.util.function.Supplier
;
import
org.apache.commons.logging.Log
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
...
@@ -68,6 +69,17 @@ class ConfigDataLocationResolversTests {
...
@@ -68,6 +69,17 @@ class ConfigDataLocationResolversTests {
private
ResourceLoader
resourceLoader
=
new
DefaultResourceLoader
();
private
ResourceLoader
resourceLoader
=
new
DefaultResourceLoader
();
@Test
void
createWhenInjectingLogAndDeferredLogFactoryCreatesResolver
()
{
ConfigDataLocationResolvers
resolvers
=
new
ConfigDataLocationResolvers
(
this
.
logFactory
,
this
.
bootstrapContext
,
this
.
binder
,
this
.
resourceLoader
,
Collections
.
singletonList
(
TestLogResolver
.
class
.
getName
()));
assertThat
(
resolvers
.
getResolvers
()).
hasSize
(
1
);
assertThat
(
resolvers
.
getResolvers
().
get
(
0
)).
isExactlyInstanceOf
(
TestLogResolver
.
class
);
TestLogResolver
resolver
=
(
TestLogResolver
)
resolvers
.
getResolvers
().
get
(
0
);
assertThat
(
resolver
.
getDeferredLogFactory
()).
isSameAs
(
this
.
logFactory
);
assertThat
(
resolver
.
getLog
()).
isNotNull
();
}
@Test
@Test
void
createWhenInjectingBinderCreatesResolver
()
{
void
createWhenInjectingBinderCreatesResolver
()
{
ConfigDataLocationResolvers
resolvers
=
new
ConfigDataLocationResolvers
(
this
.
logFactory
,
this
.
bootstrapContext
,
ConfigDataLocationResolvers
resolvers
=
new
ConfigDataLocationResolvers
(
this
.
logFactory
,
this
.
bootstrapContext
,
...
@@ -180,6 +192,27 @@ class ConfigDataLocationResolversTests {
...
@@ -180,6 +192,27 @@ class ConfigDataLocationResolversTests {
}
}
static
class
TestLogResolver
extends
TestResolver
{
private
final
DeferredLogFactory
deferredLogFactory
;
private
final
Log
log
;
TestLogResolver
(
DeferredLogFactory
deferredLogFactory
,
Log
log
)
{
this
.
deferredLogFactory
=
deferredLogFactory
;
this
.
log
=
log
;
}
DeferredLogFactory
getDeferredLogFactory
()
{
return
this
.
deferredLogFactory
;
}
Log
getLog
()
{
return
this
.
log
;
}
}
static
class
TestBoundResolver
extends
TestResolver
{
static
class
TestBoundResolver
extends
TestResolver
{
private
final
Binder
binder
;
private
final
Binder
binder
;
...
...
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