Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
schbrain-parent
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
framework
schbrain-parent
Commits
792f2539
Commit
792f2539
authored
Jul 01, 2023
by
liaozan
🏀
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace CompositePropertySource with single OrderedMapPropertySource
parent
6db1a712
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
27 deletions
+24
-27
starters/apollo-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/apollo/ConfigurablePropertiesLoader.java
...rk/autoconfigure/apollo/ConfigurablePropertiesLoader.java
+24
-27
No files found.
starters/apollo-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/apollo/ConfigurablePropertiesLoader.java
View file @
792f2539
...
...
@@ -15,7 +15,7 @@ import org.springframework.boot.logging.DeferredLogFactory;
import
org.springframework.context.ApplicationListener
;
import
org.springframework.context.event.ApplicationEventMulticaster
;
import
org.springframework.context.event.SimpleApplicationEventMulticaster
;
import
org.springframework.core.
env.CompositePropertySourc
e
;
import
org.springframework.core.
ResolvableTyp
e
;
import
org.springframework.core.env.ConfigurableEnvironment
;
import
org.springframework.util.ClassUtils
;
...
...
@@ -30,18 +30,13 @@ import static org.springframework.core.io.support.SpringFactoriesLoader.loadFact
*/
class
ConfigurablePropertiesLoader
{
/**
* the name of properties propertySource
*/
public
static
final
String
PROPERTIES_PROPERTY_SOURCE
=
"ConfigurablePropertiesPropertySource"
;
private
final
Log
log
;
private
final
DeferredLogFactory
deferredLogFactory
;
ConfigurablePropertiesLoader
(
DeferredLogFactory
deferredLogFactory
)
{
this
.
log
=
deferredLogFactory
.
getLog
(
ConfigurablePropertiesLoader
.
class
);
this
.
deferredLogFactory
=
deferredLogFactory
;
this
.
log
=
deferredLogFactory
.
getLog
(
ConfigurablePropertiesLoader
.
class
);
}
void
load
(
ConfigurableEnvironment
environment
,
SpringApplication
application
)
{
...
...
@@ -52,32 +47,34 @@ class ConfigurablePropertiesLoader {
}
ApplicationEventMulticaster
eventMulticaster
=
createEventMulticaster
(
application
.
getListeners
());
boolean
remoteFirst
=
ApolloProperties
.
get
(
environment
).
isRemoteFirst
();
ApolloProperties
apolloProperties
=
ApolloProperties
.
get
(
environment
);
// MUST NOT use CachedCompositePropertySource, because propertyNames will be cached when property loading
CompositePropertySource
compositePropertySource
=
new
CompositePropertySource
(
PROPERTIES_PROPERTY_SOURCE
);
if
(
apolloProperties
.
isRemoteFirst
())
{
environment
.
getPropertySources
().
addFirst
(
compositePropertySource
);
}
else
{
environment
.
getPropertySources
().
addLast
(
compositePropertySource
);
configurableProperties
.
parallelStream
().
forEach
(
properties
->
{
OrderedMapPropertySource
propertySource
=
loadFromRemote
(
environment
,
remoteFirst
,
properties
.
getNamespace
());
if
(
propertySource
==
null
)
{
return
;
}
// multicast event
ConfigLoadedEvent
event
=
createEvent
(
environment
,
application
,
propertySource
,
properties
);
eventMulticaster
.
multicastEvent
(
event
,
ResolvableType
.
forClass
(
event
.
getClass
()));
});
}
configurableProperties
.
forEach
(
properties
->
{
String
namespace
=
properties
.
getNamespace
();
private
OrderedMapPropertySource
loadFromRemote
(
ConfigurableEnvironment
environment
,
boolean
remoteFirst
,
String
namespace
)
{
Config
config
=
ConfigService
.
getConfig
(
namespace
);
OrderedMapPropertySource
propertySource
=
ConfigUtils
.
toPropertySource
(
namespace
,
config
);
if
(
propertySource
==
null
)
{
log
.
warn
(
"No configuration properties loaded under namespace: "
+
namespace
);
return
;
return
null
;
}
if
(
remoteFirst
)
{
environment
.
getPropertySources
().
addFirst
(
propertySource
);
}
else
{
environment
.
getPropertySources
().
addLast
(
propertySource
);
}
// early add to environment to support properties bind
compositePropertySource
.
addPropertySource
(
propertySource
);
// resolve any placeHolders
ConfigUtils
.
resolvePlaceHolders
(
environment
,
propertySource
);
// multicast event
eventMulticaster
.
multicastEvent
(
createEvent
(
environment
,
application
,
propertySource
,
properties
));
});
return
propertySource
;
}
private
ConfigLoadedEvent
createEvent
(
ConfigurableEnvironment
environment
,
SpringApplication
application
,
...
...
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