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
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
panwangnan
schbrain-parent
Commits
34d85888
Commit
34d85888
authored
May 08, 2023
by
liaozan
🏀
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor dubbo properties load
parent
ecb37261
Changes
9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
2363 additions
and
38 deletions
+2363
-38
commons/common-util/src/main/java/com/schbrain/common/util/properties/OrderedMapPropertySource.java
...rain/common/util/properties/OrderedMapPropertySource.java
+4
-0
integration/integration-jenkins-plugin/pom.xml
integration/integration-jenkins-plugin/pom.xml
+1
-0
starters/apollo-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/apollo/ApolloConfigurationInitializerEnvironmentPostProcessor.java
...olloConfigurationInitializerEnvironmentPostProcessor.java
+4
-1
starters/apollo-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/apollo/ConfigurablePropertiesLoader.java
...rk/autoconfigure/apollo/ConfigurablePropertiesLoader.java
+5
-10
starters/apollo-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/apollo/event/PropertiesPreparedEvent.java
...k/autoconfigure/apollo/event/PropertiesPreparedEvent.java
+3
-3
starters/dubbo-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/dubbo/listener/DubboConfigInitEventListener.java
...onfigure/dubbo/listener/DubboConfigInitEventListener.java
+49
-0
starters/dubbo-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/dubbo/listener/DubboPropertiesPreparedEventListener.java
.../dubbo/listener/DubboPropertiesPreparedEventListener.java
+17
-23
starters/dubbo-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/dubbo/properties/DubboProperties.java
...ework/autoconfigure/dubbo/properties/DubboProperties.java
+61
-0
starters/dubbo-spring-boot-starter/src/main/resources/META-INF/spring-configuration-metadata.json
...ain/resources/META-INF/spring-configuration-metadata.json
+2219
-1
No files found.
commons/common-util/src/main/java/com/schbrain/common/util/properties/OrderedMapPropertySource.java
View file @
34d85888
...
...
@@ -21,4 +21,8 @@ public class OrderedMapPropertySource extends MapPropertySource {
getSource
().
putAll
(
properties
);
}
public
void
addProperty
(
String
propertyName
,
String
propertyValue
)
{
getSource
().
put
(
propertyName
,
propertyValue
);
}
}
\ No newline at end of file
integration/integration-jenkins-plugin/pom.xml
View file @
34d85888
...
...
@@ -24,6 +24,7 @@
<properties>
<jenkins.version>
2.397
</jenkins.version>
<maven.install.skip>
true
</maven.install.skip>
<maven.deploy.skip>
true
</maven.deploy.skip>
<spotbugs.skip>
true
</spotbugs.skip>
<enforcer.skip>
true
</enforcer.skip>
...
...
starters/apollo-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/apollo/ApolloConfigurationInitializerEnvironmentPostProcessor.java
View file @
34d85888
...
...
@@ -34,8 +34,11 @@ public class ApolloConfigurationInitializerEnvironmentPostProcessor extends Logg
private
static
Map
<
String
,
Object
>
INIT_PROPERTIES
=
new
LinkedHashMap
<>();
private
final
ConfigurablePropertiesLoader
configurablePropertiesLoader
;
public
ApolloConfigurationInitializerEnvironmentPostProcessor
(
DeferredLogFactory
deferredLogFactory
,
ConfigurableBootstrapContext
bootstrapContext
)
{
super
(
deferredLogFactory
,
bootstrapContext
);
this
.
configurablePropertiesLoader
=
new
ConfigurablePropertiesLoader
(
deferredLogFactory
);
}
@Override
...
...
@@ -45,7 +48,7 @@ public class ApolloConfigurationInitializerEnvironmentPostProcessor extends Logg
return
;
}
setRequiredProperty
(
environment
);
new
ConfigurablePropertiesLoader
(
deferredLogFactory
,
environment
,
application
).
load
(
);
configurablePropertiesLoader
.
load
(
environment
,
application
);
}
@Override
...
...
starters/apollo-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/apollo/ConfigurablePropertiesLoader.java
View file @
34d85888
...
...
@@ -38,18 +38,12 @@ class ConfigurablePropertiesLoader {
private
final
DeferredLogFactory
deferredLogFactory
;
private
final
ConfigurableEnvironment
environment
;
private
final
SpringApplication
application
;
ConfigurablePropertiesLoader
(
DeferredLogFactory
deferredLogFactory
,
ConfigurableEnvironment
environment
,
SpringApplication
application
)
{
ConfigurablePropertiesLoader
(
DeferredLogFactory
deferredLogFactory
)
{
this
.
log
=
deferredLogFactory
.
getLog
(
ConfigurablePropertiesLoader
.
class
);
this
.
deferredLogFactory
=
deferredLogFactory
;
this
.
environment
=
environment
;
this
.
application
=
application
;
}
void
load
()
{
void
load
(
ConfigurableEnvironment
environment
,
SpringApplication
application
)
{
List
<
ConfigurableProperties
>
configurableProperties
=
loadFactories
(
ConfigurableProperties
.
class
,
getClass
().
getClassLoader
());
if
(
CollectionUtils
.
isEmpty
(
configurableProperties
))
{
log
.
warn
(
"There is no configuration properties found"
);
...
...
@@ -81,11 +75,12 @@ class ConfigurablePropertiesLoader {
// resolve any placeHolders
ConfigUtils
.
resolvePlaceHolders
(
environment
,
propertySource
);
// multicast event
eventMulticaster
.
multicastEvent
(
createEvent
(
propertySource
,
properties
));
eventMulticaster
.
multicastEvent
(
createEvent
(
environment
,
application
,
propertySource
,
properties
));
});
}
private
PropertiesPreparedEvent
createEvent
(
OrderedMapPropertySource
propertySource
,
ConfigurableProperties
properties
)
{
private
PropertiesPreparedEvent
createEvent
(
ConfigurableEnvironment
environment
,
SpringApplication
application
,
OrderedMapPropertySource
propertySource
,
ConfigurableProperties
properties
)
{
ConfigurableProperties
boundProperties
=
properties
.
bind
(
environment
);
return
new
PropertiesPreparedEvent
(
environment
,
deferredLogFactory
,
propertySource
,
boundProperties
,
application
);
}
...
...
starters/apollo-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/apollo/event/PropertiesPreparedEvent.java
View file @
34d85888
...
...
@@ -23,18 +23,18 @@ public class PropertiesPreparedEvent extends ApplicationEvent {
private
final
OrderedMapPropertySource
propertySource
;
private
final
SpringApplication
a
pplication
;
private
final
SpringApplication
springA
pplication
;
public
PropertiesPreparedEvent
(
ConfigurableEnvironment
environment
,
DeferredLogFactory
deferredLogFactory
,
OrderedMapPropertySource
propertySource
,
ConfigurableProperties
properties
,
SpringApplication
a
pplication
)
{
SpringApplication
springA
pplication
)
{
super
(
properties
);
this
.
environment
=
environment
;
this
.
propertySource
=
propertySource
;
this
.
deferredLogFactory
=
deferredLogFactory
;
this
.
application
=
a
pplication
;
this
.
springApplication
=
springA
pplication
;
}
public
ConfigurableProperties
getConfigurableProperties
()
{
...
...
starters/dubbo-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/dubbo/listener/DubboConfigInitEventListener.java
0 → 100644
View file @
34d85888
package
com.schbrain.framework.autoconfigure.dubbo.listener
;
import
org.apache.dubbo.config.ConfigCenterConfig
;
import
org.apache.dubbo.config.context.ConfigManager
;
import
org.apache.dubbo.config.spring.context.event.DubboConfigInitEvent
;
import
org.apache.dubbo.config.spring.util.DubboBeanUtils
;
import
org.apache.dubbo.rpc.model.ApplicationModel
;
import
org.springframework.context.ApplicationListener
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.core.PriorityOrdered
;
import
java.util.Map
;
import
static
org
.
apache
.
dubbo
.
config
.
spring
.
util
.
EnvironmentUtils
.
filterDubboProperties
;
/**
* @author liaozan
* @since 2023-05-08
*/
class
DubboConfigInitEventListener
implements
ApplicationListener
<
DubboConfigInitEvent
>,
PriorityOrdered
{
private
final
ConfigurableApplicationContext
applicationContext
;
DubboConfigInitEventListener
(
ConfigurableApplicationContext
applicationContext
)
{
this
.
applicationContext
=
applicationContext
;
}
@Override
public
void
onApplicationEvent
(
DubboConfigInitEvent
event
)
{
if
(
event
.
getApplicationContext
()
==
applicationContext
)
{
ApplicationModel
applicationModel
=
DubboBeanUtils
.
getApplicationModel
(
applicationContext
);
ConfigManager
configManager
=
applicationModel
.
getApplicationConfigManager
();
configManager
.
addConfigCenter
(
buildConfigCenterConfig
());
}
}
@Override
public
int
getOrder
()
{
return
HIGHEST_PRECEDENCE
;
}
private
ConfigCenterConfig
buildConfigCenterConfig
()
{
Map
<
String
,
String
>
externalConfiguration
=
filterDubboProperties
(
applicationContext
.
getEnvironment
());
ConfigCenterConfig
configCenterConfig
=
new
ConfigCenterConfig
();
configCenterConfig
.
setExternalConfig
(
externalConfiguration
);
return
configCenterConfig
;
}
}
\ No newline at end of file
starters/dubbo-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/dubbo/listener/DubboPropertiesPreparedEventListener.java
View file @
34d85888
package
com.schbrain.framework.autoconfigure.dubbo.listener
;
import
com.alibaba.fastjson2.JSONFactory
;
import
com.google.common.collect.Maps
;
import
com.schbrain.common.util.ApplicationName
;
import
com.schbrain.common.util.properties.OrderedMapPropertySource
;
import
com.schbrain.framework.autoconfigure.apollo.event.PropertiesPreparedEvent
;
import
com.schbrain.framework.autoconfigure.apollo.event.listener.GenericPropertiesPreparedEventListener
;
import
com.schbrain.framework.autoconfigure.dubbo.properties.DubboProperties
;
import
org.apache.dubbo.config.bootstrap.DubboBootstrap
;
import
org.apache.dubbo.config.spring.ConfigCenterBean
;
import
org.apache.dubbo.config.spring.util.EnvironmentUtils
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.context.ApplicationContextInitializer
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.core.Ordered
;
import
org.springframework.core.env.ConfigurableEnvironment
;
import
java.util.Map
;
import
java.util.SortedMap
;
import
static
org
.
apache
.
dubbo
.
config
.
ConfigKeys
.
DUBBO_SCAN_BASE_PACKAGES
;
/**
* @author liaozan
* @since 2023-04-28
*/
public
class
DubboPropertiesPreparedEventListener
extends
GenericPropertiesPreparedEventListener
<
DubboProperties
>
{
public
class
DubboPropertiesPreparedEventListener
extends
GenericPropertiesPreparedEventListener
<
DubboProperties
>
implements
ApplicationContextInitializer
<
ConfigurableApplicationContext
>
{
public
static
final
String
DUBBO_APPLICATION_NAME
=
"dubbo.application.name"
;
...
...
@@ -32,26 +28,24 @@ public class DubboPropertiesPreparedEventListener extends GenericPropertiesPrepa
}
@Override
protected
void
onPropertiesPrepared
(
PropertiesPreparedEvent
event
,
DubboProperties
properties
)
{
ConfigurableEnvironment
environment
=
event
.
getEnvironment
();
Map
<
String
,
String
>
requiredProperties
=
collectRequiredProperties
(
environment
,
event
.
getApplication
());
event
.
getPropertySource
().
addProperties
(
requiredProperties
);
injectDubboProperties
(
environment
);
public
void
initialize
(
ConfigurableApplicationContext
applicationContext
)
{
applicationContext
.
addApplicationListener
(
new
DubboConfigInitEventListener
(
applicationContext
));
}
private
void
injectDubboProperties
(
ConfigurableEnvironment
environment
)
{
@Override
protected
void
onPropertiesPrepared
(
PropertiesPreparedEvent
event
,
DubboProperties
properties
)
{
event
.
getSpringApplication
().
addInitializers
(
this
);
setRequiredProperties
(
event
.
getEnvironment
(),
event
.
getSpringApplication
(),
event
.
getPropertySource
());
JSONFactory
.
setUseJacksonAnnotation
(
false
);
SortedMap
<
String
,
String
>
dubboProperties
=
EnvironmentUtils
.
filterDubboProperties
(
environment
);
ConfigCenterBean
configCenterBean
=
new
ConfigCenterBean
();
configCenterBean
.
setExternalConfig
(
dubboProperties
);
DubboBootstrap
.
getInstance
().
configCenter
(
configCenterBean
);
}
private
Map
<
String
,
String
>
collectRequiredProperties
(
ConfigurableEnvironment
environment
,
SpringApplication
application
)
{
Map
<
String
,
String
>
dubboRequiredProperties
=
Maps
.
newLinkedHashMapWithExpectedSize
(
2
);
dubboRequiredProperties
.
put
(
DUBBO_SCAN_BASE_PACKAGES
,
getBasePackage
(
application
));
dubboRequiredProperties
.
put
(
DUBBO_APPLICATION_NAME
,
ApplicationName
.
get
(
environment
));
return
dubboRequiredProperties
;
private
void
setRequiredProperties
(
ConfigurableEnvironment
environment
,
SpringApplication
application
,
OrderedMapPropertySource
propertySource
)
{
if
(!
propertySource
.
containsProperty
(
DUBBO_SCAN_BASE_PACKAGES
))
{
propertySource
.
addProperty
(
DUBBO_SCAN_BASE_PACKAGES
,
getBasePackage
(
application
));
}
if
(!
propertySource
.
containsProperty
(
DUBBO_APPLICATION_NAME
))
{
propertySource
.
addProperty
(
DUBBO_APPLICATION_NAME
,
ApplicationName
.
get
(
environment
));
}
}
private
String
getBasePackage
(
SpringApplication
application
)
{
...
...
starters/dubbo-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/dubbo/properties/DubboProperties.java
View file @
34d85888
...
...
@@ -3,7 +3,13 @@ package com.schbrain.framework.autoconfigure.dubbo.properties;
import
com.schbrain.common.util.support.ConfigurableProperties
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
import
org.apache.dubbo.config.*
;
import
org.apache.dubbo.config.spring.context.annotation.EnableDubbo
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.boot.context.properties.NestedConfigurationProperty
;
import
java.util.LinkedHashSet
;
import
java.util.Set
;
/**
* used to fetch dubbo.* config from remote
...
...
@@ -16,9 +22,64 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties
(
prefix
=
"dubbo"
)
public
class
DubboProperties
extends
ConfigurableProperties
{
@NestedConfigurationProperty
private
Scan
scan
=
new
Scan
();
@NestedConfigurationProperty
private
ApplicationConfig
application
=
new
ApplicationConfig
();
@NestedConfigurationProperty
private
ModuleConfig
module
=
new
ModuleConfig
();
@NestedConfigurationProperty
private
RegistryConfig
registry
=
new
RegistryConfig
();
@NestedConfigurationProperty
private
ProtocolConfig
protocol
=
new
ProtocolConfig
();
@NestedConfigurationProperty
private
MonitorConfig
monitor
=
new
MonitorConfig
();
@NestedConfigurationProperty
private
ProviderConfig
provider
=
new
ProviderConfig
();
@NestedConfigurationProperty
private
ConsumerConfig
consumer
=
new
ConsumerConfig
();
@NestedConfigurationProperty
private
ConfigCenterConfig
configCenter
=
new
ConfigCenterConfig
();
@NestedConfigurationProperty
private
MetadataReportConfig
metadataReport
=
new
MetadataReportConfig
();
@NestedConfigurationProperty
private
MetricsConfig
metrics
=
new
MetricsConfig
();
@NestedConfigurationProperty
private
TracingConfig
tracing
=
new
TracingConfig
();
@Override
public
String
getDefaultNamespace
()
{
return
"dubbo-common"
;
}
static
class
Scan
{
/**
* The basePackages to scan , the multiple-value is delimited by comma
*
* @see EnableDubbo#scanBasePackages()
*/
private
Set
<
String
>
basePackages
=
new
LinkedHashSet
<>();
public
Set
<
String
>
getBasePackages
()
{
return
basePackages
;
}
public
void
setBasePackages
(
Set
<
String
>
basePackages
)
{
this
.
basePackages
=
basePackages
;
}
}
}
\ No newline at end of file
starters/dubbo-spring-boot-starter/src/main/resources/META-INF/spring-configuration-metadata.json
View file @
34d85888
This diff is collapsed.
Click to expand it.
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