Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
caopu16
whatsmars
提交
82fcd480
W
whatsmars
项目概览
caopu16
/
whatsmars
与 Fork 源项目一致
Fork自
武汉红喜 / whatsmars
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
W
whatsmars
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
82fcd480
编写于
1月 23, 2018
作者:
武汉红喜
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
重写spring-boot-starter-dubbo
上级
cdb18839
变更
19
隐藏空白更改
内联
并排
Showing
19 changed file
with
807 addition
and
211 deletion
+807
-211
whatsmars-dubbo/whatsmars-dubbo-consumer-boot/src/main/java/org/hongxi/whatsmars/dubbo/demo/consumer/ConsumerApplication.java
...xi/whatsmars/dubbo/demo/consumer/ConsumerApplication.java
+0
-2
whatsmars-dubbo/whatsmars-dubbo-consumer-boot/src/main/resources/application.yml
...rs-dubbo-consumer-boot/src/main/resources/application.yml
+16
-8
whatsmars-dubbo/whatsmars-dubbo-provider-boot/src/main/java/org/hongxi/whatsmars/dubbo/demo/provider/ProviderApplication.java
...xi/whatsmars/dubbo/demo/provider/ProviderApplication.java
+2
-3
whatsmars-dubbo/whatsmars-dubbo-provider-boot/src/main/java/org/hongxi/whatsmars/dubbo/demo/provider/service/DemoServiceImpl.java
...hatsmars/dubbo/demo/provider/service/DemoServiceImpl.java
+7
-2
whatsmars-dubbo/whatsmars-dubbo-provider-boot/src/main/resources/application.yml
...rs-dubbo-provider-boot/src/main/resources/application.yml
+15
-18
whatsmars-dubbo/whatsmars-dubbo-starter/pom.xml
whatsmars-dubbo/whatsmars-dubbo-starter/pom.xml
+4
-0
whatsmars-dubbo/whatsmars-dubbo-starter/src/main/java/org/hongxi/whatsmars/dubbo/starter/DubboAutoConfiguration.java
...ongxi/whatsmars/dubbo/starter/DubboAutoConfiguration.java
+0
-88
whatsmars-dubbo/whatsmars-dubbo-starter/src/main/java/org/hongxi/whatsmars/dubbo/starter/DubboConfigurationApplicationContextInitializer.java
...rter/DubboConfigurationApplicationContextInitializer.java
+0
-28
whatsmars-dubbo/whatsmars-dubbo-starter/src/main/java/org/hongxi/whatsmars/dubbo/starter/DubboHolderListener.java
...g/hongxi/whatsmars/dubbo/starter/DubboHolderListener.java
+0
-57
whatsmars-dubbo/whatsmars-dubbo-starter/src/main/java/org/hongxi/whatsmars/dubbo/starter/autoconfigure/DubboAutoConfiguration.java
...s/dubbo/starter/autoconfigure/DubboAutoConfiguration.java
+94
-0
whatsmars-dubbo/whatsmars-dubbo-starter/src/main/java/org/hongxi/whatsmars/dubbo/starter/autoconfigure/DubboConfigProperties.java
...rs/dubbo/starter/autoconfigure/DubboConfigProperties.java
+44
-0
whatsmars-dubbo/whatsmars-dubbo-starter/src/main/java/org/hongxi/whatsmars/dubbo/starter/autoconfigure/DubboScanProperties.java
...mars/dubbo/starter/autoconfigure/DubboScanProperties.java
+36
-0
whatsmars-dubbo/whatsmars-dubbo-starter/src/main/java/org/hongxi/whatsmars/dubbo/starter/autoconfigure/MultipleDubboConfigBindingProperties.java
...r/autoconfigure/MultipleDubboConfigBindingProperties.java
+123
-0
whatsmars-dubbo/whatsmars-dubbo-starter/src/main/java/org/hongxi/whatsmars/dubbo/starter/autoconfigure/SingleDubboConfigBindingProperties.java
...ter/autoconfigure/SingleDubboConfigBindingProperties.java
+119
-0
whatsmars-dubbo/whatsmars-dubbo-starter/src/main/java/org/hongxi/whatsmars/dubbo/starter/context/event/OverrideDubboConfigApplicationListener.java
...context/event/OverrideDubboConfigApplicationListener.java
+66
-0
whatsmars-dubbo/whatsmars-dubbo-starter/src/main/java/org/hongxi/whatsmars/dubbo/starter/context/event/WelcomeLogoApplicationListener.java
...starter/context/event/WelcomeLogoApplicationListener.java
+66
-0
whatsmars-dubbo/whatsmars-dubbo-starter/src/main/java/org/hongxi/whatsmars/dubbo/starter/util/DubboUtils.java
...a/org/hongxi/whatsmars/dubbo/starter/util/DubboUtils.java
+121
-0
whatsmars-dubbo/whatsmars-dubbo-starter/src/main/java/org/hongxi/whatsmars/dubbo/starter/util/EnvironmentUtils.java
...hongxi/whatsmars/dubbo/starter/util/EnvironmentUtils.java
+88
-0
whatsmars-dubbo/whatsmars-dubbo-starter/src/main/resources/META-INF/spring.factories
...ubbo-starter/src/main/resources/META-INF/spring.factories
+6
-5
未找到文件。
whatsmars-dubbo/whatsmars-dubbo-consumer-boot/src/main/java/org/hongxi/whatsmars/dubbo/demo/consumer/ConsumerApplication.java
浏览文件 @
82fcd480
package
org.hongxi.whatsmars.dubbo.demo.consumer
;
import
com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo
;
import
org.hongxi.whatsmars.dubbo.demo.consumer.rpc.DemoRpc
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
...
...
@@ -10,7 +9,6 @@ import org.springframework.context.ConfigurableApplicationContext;
* Created by javahongxi on 2017/12/4.
*/
@SpringBootApplication
@EnableDubbo
(
scanBasePackages
=
"org.hongxi.whatsmars.dubbo.demo.consumer.rpc"
,
multipleConfig
=
true
)
public
class
ConsumerApplication
{
public
static
void
main
(
String
[]
args
)
{
ConfigurableApplicationContext
context
=
SpringApplication
.
run
(
ConsumerApplication
.
class
,
args
);
...
...
whatsmars-dubbo/whatsmars-dubbo-consumer-boot/src/main/resources/application.yml
浏览文件 @
82fcd480
spring
:
dubbo
:
application
:
name
:
demo-consumer
registry
:
address
:
zookeeper://127.0.0.1:2181
module
:
name
:
demo
# scan:
\ No newline at end of file
application
:
name
:
demo-consumer
dubbo
:
registry
:
address
:
zookeeper://127.0.0.1:2181
id
:
my-registry
protocol
:
port
:
20882
name
:
dubbo
id
:
dubbo
application
:
name
:
demo-consumer
id
:
demo-consumer
qos
:
port
:
22223
whatsmars-dubbo/whatsmars-dubbo-provider-boot/src/main/java/org/hongxi/whatsmars/dubbo/demo/provider/ProviderApplication.java
浏览文件 @
82fcd480
package
org.hongxi.whatsmars.dubbo.demo.provider
;
import
com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.context.annotation.ComponentScan
;
...
...
@@ -10,9 +9,9 @@ import org.springframework.context.annotation.ComponentScan;
*/
@SpringBootApplication
@ComponentScan
(
value
=
{
"org.hongxi.whatsmars.dubbo"
})
@EnableDubbo
(
scanBasePackages
=
"org.hongxi.whatsmars.dubbo.demo.provider.resource"
,
multipleConfig
=
true
)
public
class
ProviderApplication
{
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
SpringApplication
.
run
(
ProviderApplication
.
class
,
args
);
System
.
in
.
read
();
}
}
whatsmars-dubbo/whatsmars-dubbo-provider-boot/src/main/java/org/hongxi/whatsmars/dubbo/demo/provider/
resour
ce/DemoServiceImpl.java
→
whatsmars-dubbo/whatsmars-dubbo-provider-boot/src/main/java/org/hongxi/whatsmars/dubbo/demo/provider/
servi
ce/DemoServiceImpl.java
浏览文件 @
82fcd480
/**
* Created by shenhongxi on 2017/12/4.
*/
package
org.hongxi.whatsmars.dubbo.demo.provider.
resour
ce
;
package
org.hongxi.whatsmars.dubbo.demo.provider.
servi
ce
;
import
com.alibaba.dubbo.config.annotation.Service
;
import
com.alibaba.dubbo.rpc.RpcContext
;
...
...
@@ -12,7 +12,12 @@ import org.springframework.beans.factory.annotation.Autowired;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
@Service
(
version
=
"1.0.0"
)
@Service
(
version
=
"1.0.0"
,
application
=
"${dubbo.application.id}"
,
protocol
=
"${dubbo.protocol.id}"
,
registry
=
"${dubbo.registry.id}"
)
public
class
DemoServiceImpl
implements
DemoService
{
@Autowired
...
...
whatsmars-dubbo/whatsmars-dubbo-provider-boot/src/main/resources/application.yml
浏览文件 @
82fcd480
spring
:
dubbo
:
application
:
name
:
demo-provider
registry
:
address
:
zookeeper://127.0.0.1:2181
protocol
:
name
:
dubbo
port
:
20881
module
:
name
:
demo
# scan:
application
:
name
:
demo-provider
# protocol:
# dubbo:
# name: dubbo
# port: 20881
# hessian:
# name: hessian
# port: 8080
\ No newline at end of file
dubbo
:
registry
:
address
:
zookeeper://127.0.0.1:2181
id
:
my-registry
protocol
:
port
:
20882
name
:
dubbo
id
:
dubbo
application
:
name
:
demo-provider
id
:
demo-provider
scan
:
basePackages
:
org.hongxi.whatsmars.dubbo.demo.provider.service
whatsmars-dubbo/whatsmars-dubbo-starter/pom.xml
浏览文件 @
82fcd480
...
...
@@ -28,6 +28,10 @@
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-configuration-processor
</artifactId>
</dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
dubbo
</artifactId>
...
...
whatsmars-dubbo/whatsmars-dubbo-starter/src/main/java/org/hongxi/whatsmars/dubbo/starter/DubboAutoConfiguration.java
已删除
100644 → 0
浏览文件 @
cdb18839
package
org.hongxi.whatsmars.dubbo.starter
;
import
com.alibaba.dubbo.config.*
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
@Configuration
@EnableConfigurationProperties
(
DubboProperties
.
class
)
public
class
DubboAutoConfiguration
{
@Autowired
private
DubboProperties
dubboProperties
;
@Bean
public
ApplicationConfig
applicationConfig
()
{
ApplicationConfig
applicationConfig
=
dubboProperties
.
getApplication
();
if
(
applicationConfig
==
null
)
{
applicationConfig
=
new
ApplicationConfig
();
}
return
applicationConfig
;
}
@Bean
public
RegistryConfig
registryConfig
()
{
RegistryConfig
registryConfig
=
dubboProperties
.
getRegistry
();
if
(
registryConfig
==
null
)
{
registryConfig
=
new
RegistryConfig
();
}
return
registryConfig
;
}
@Bean
public
ProtocolConfig
protocolConfig
()
{
ProtocolConfig
protocolConfig
=
dubboProperties
.
getProtocol
();
if
(
protocolConfig
==
null
)
{
protocolConfig
=
new
ProtocolConfig
();
}
return
protocolConfig
;
}
@Bean
public
MonitorConfig
monitorConfig
()
{
MonitorConfig
monitorConfig
=
dubboProperties
.
getMonitor
();
if
(
monitorConfig
==
null
)
{
monitorConfig
=
new
MonitorConfig
();
}
return
monitorConfig
;
}
@Bean
public
ProviderConfig
providerConfig
()
{
ProviderConfig
providerConfig
=
dubboProperties
.
getProvider
();
if
(
providerConfig
==
null
)
{
providerConfig
=
new
ProviderConfig
();
}
return
providerConfig
;
}
@Bean
public
ModuleConfig
moduleConfig
()
{
ModuleConfig
moduleConfig
=
dubboProperties
.
getModule
();
if
(
moduleConfig
==
null
)
{
moduleConfig
=
new
ModuleConfig
();
}
return
moduleConfig
;
}
@Bean
public
MethodConfig
methodConfig
()
{
MethodConfig
methodConfig
=
dubboProperties
.
getMethod
();
if
(
methodConfig
==
null
)
{
methodConfig
=
new
MethodConfig
();
}
return
methodConfig
;
}
@Bean
public
ConsumerConfig
consumerConfig
()
{
ConsumerConfig
consumerConfig
=
dubboProperties
.
getConsumer
();
if
(
consumerConfig
==
null
)
{
consumerConfig
=
new
ConsumerConfig
();
}
return
consumerConfig
;
}
}
whatsmars-dubbo/whatsmars-dubbo-starter/src/main/java/org/hongxi/whatsmars/dubbo/starter/DubboConfigurationApplicationContextInitializer.java
已删除
100644 → 0
浏览文件 @
cdb18839
package
org.hongxi.whatsmars.dubbo.starter
;
import
com.alibaba.dubbo.config.spring.AnnotationBean
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.context.ApplicationContextInitializer
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.core.env.Environment
;
@Deprecated
public
class
DubboConfigurationApplicationContextInitializer
implements
ApplicationContextInitializer
<
ConfigurableApplicationContext
>
{
@Override
public
void
initialize
(
ConfigurableApplicationContext
applicationContext
)
{
Environment
env
=
applicationContext
.
getEnvironment
();
String
scan
=
env
.
getProperty
(
"spring.dubbo.scan"
);
if
(
scan
!=
null
)
{
AnnotationBean
scanner
=
BeanUtils
.
instantiate
(
AnnotationBean
.
class
);
scanner
.
setPackage
(
scan
);
scanner
.
setApplicationContext
(
applicationContext
);
applicationContext
.
addBeanFactoryPostProcessor
(
scanner
);
applicationContext
.
getBeanFactory
().
addBeanPostProcessor
(
scanner
);
applicationContext
.
getBeanFactory
().
registerSingleton
(
"annotationBean"
,
scanner
);
}
}
}
whatsmars-dubbo/whatsmars-dubbo-starter/src/main/java/org/hongxi/whatsmars/dubbo/starter/DubboHolderListener.java
已删除
100644 → 0
浏览文件 @
cdb18839
package
org.hongxi.whatsmars.dubbo.starter
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.boot.context.event.ApplicationPreparedEvent
;
import
org.springframework.context.ApplicationEvent
;
import
org.springframework.context.ApplicationListener
;
import
org.springframework.context.event.ContextClosedEvent
;
@SuppressWarnings
(
"rawtypes"
)
public
class
DubboHolderListener
implements
ApplicationListener
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
DubboHolderListener
.
class
);
private
static
Thread
holdThread
;
private
static
Boolean
running
=
Boolean
.
FALSE
;
@Override
public
void
onApplicationEvent
(
ApplicationEvent
event
)
{
if
(
event
instanceof
ApplicationPreparedEvent
)
{
if
(
running
==
Boolean
.
FALSE
)
running
=
Boolean
.
TRUE
;
if
(
holdThread
==
null
)
{
holdThread
=
new
Thread
(
new
Runnable
()
{
@Override
public
void
run
()
{
if
(
LOGGER
.
isTraceEnabled
())
{
LOGGER
.
trace
(
Thread
.
currentThread
().
getName
());
}
while
(
running
&&
!
Thread
.
currentThread
().
isInterrupted
())
{
try
{
Thread
.
sleep
(
2000
);
}
catch
(
InterruptedException
e
)
{
}
}
}
},
"Dubbo-Holder"
);
holdThread
.
setDaemon
(
false
);
holdThread
.
start
();
}
}
if
(
event
instanceof
ContextClosedEvent
)
{
running
=
Boolean
.
FALSE
;
if
(
null
!=
holdThread
)
{
holdThread
.
interrupt
();
holdThread
=
null
;
}
}
}
public
static
void
stopApplicationContext
(
Boolean
stop
){
running
=
stop
.
booleanValue
();
if
(
null
!=
holdThread
)
{
holdThread
.
interrupt
();
holdThread
=
null
;
}
}
}
whatsmars-dubbo/whatsmars-dubbo-starter/src/main/java/org/hongxi/whatsmars/dubbo/starter/autoconfigure/DubboAutoConfiguration.java
0 → 100644
浏览文件 @
82fcd480
package
org.hongxi.whatsmars.dubbo.starter.autoconfigure
;
import
com.alibaba.dubbo.config.AbstractConfig
;
import
com.alibaba.dubbo.config.ApplicationConfig
;
import
com.alibaba.dubbo.config.annotation.Reference
;
import
com.alibaba.dubbo.config.annotation.Service
;
import
com.alibaba.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor
;
import
com.alibaba.dubbo.config.spring.beans.factory.annotation.ServiceAnnotationBeanPostProcessor
;
import
com.alibaba.dubbo.config.spring.context.annotation.DubboComponentScan
;
import
com.alibaba.dubbo.config.spring.context.annotation.DubboConfigConfiguration
;
import
com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo
;
import
com.alibaba.dubbo.config.spring.context.annotation.EnableDubboConfig
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.boot.bind.RelaxedPropertyResolver
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.core.env.Environment
;
import
java.util.Set
;
import
static
org
.
hongxi
.
whatsmars
.
dubbo
.
starter
.
util
.
DubboUtils
.*;
import
static
java
.
util
.
Collections
.
emptySet
;
/**
* Dubbo Auto {@link Configuration}
*
* @see ApplicationConfig
* @see Service
* @see Reference
* @see DubboComponentScan
* @see EnableDubboConfig
* @see EnableDubbo
*/
@Configuration
@ConditionalOnProperty
(
prefix
=
DUBBO_PREFIX
,
name
=
"enabled"
,
matchIfMissing
=
true
,
havingValue
=
"true"
)
@ConditionalOnClass
(
AbstractConfig
.
class
)
@EnableConfigurationProperties
(
value
=
{
DubboScanProperties
.
class
,
DubboConfigProperties
.
class
})
public
class
DubboAutoConfiguration
{
/**
* Single Dubbo Config Configuration
*
* @see EnableDubboConfig
* @see DubboConfigConfiguration.Single
*/
@ConditionalOnProperty
(
name
=
MULTIPLE_CONFIG_PROPERTY_NAME
,
havingValue
=
"false"
,
matchIfMissing
=
true
)
@EnableDubboConfig
@EnableConfigurationProperties
(
SingleDubboConfigBindingProperties
.
class
)
protected
static
class
SingleDubboConfigConfiguration
{
}
/**
* Multiple Dubbo Config Configuration , equals {@link EnableDubboConfig#multiple()} == <code>true</code>
*
* @see EnableDubboConfig#multiple()
* @see DubboConfigConfiguration.Multiple
*/
@ConditionalOnProperty
(
name
=
MULTIPLE_CONFIG_PROPERTY_NAME
,
havingValue
=
"true"
)
@EnableDubboConfig
(
multiple
=
true
)
@EnableConfigurationProperties
(
MultipleDubboConfigBindingProperties
.
class
)
protected
static
class
MultipleDubboConfigConfiguration
{
}
/**
* Creates {@link ServiceAnnotationBeanPostProcessor} Bean
*
* @return {@link ServiceAnnotationBeanPostProcessor}
*/
@ConditionalOnProperty
(
name
=
BASE_PACKAGES_PROPERTY_NAME
)
@Autowired
@Bean
public
ServiceAnnotationBeanPostProcessor
serviceAnnotationBeanPostProcessor
(
Environment
environment
)
{
RelaxedPropertyResolver
resolver
=
new
RelaxedPropertyResolver
(
environment
);
Set
<
String
>
packagesToScan
=
resolver
.
getProperty
(
BASE_PACKAGES_PROPERTY_NAME
,
Set
.
class
,
emptySet
());
return
new
ServiceAnnotationBeanPostProcessor
(
packagesToScan
);
}
/**
* Creates {@link ReferenceAnnotationBeanPostProcessor} Bean if Absent
*
* @return {@link ReferenceAnnotationBeanPostProcessor}
*/
@ConditionalOnMissingBean
@Bean
(
name
=
ReferenceAnnotationBeanPostProcessor
.
BEAN_NAME
)
public
ReferenceAnnotationBeanPostProcessor
referenceAnnotationBeanPostProcessor
()
{
return
new
ReferenceAnnotationBeanPostProcessor
();
}
}
whatsmars-dubbo/whatsmars-dubbo-starter/src/main/java/org/hongxi/whatsmars/dubbo/starter/autoconfigure/DubboConfigProperties.java
0 → 100644
浏览文件 @
82fcd480
package
org.hongxi.whatsmars.dubbo.starter.autoconfigure
;
import
com.alibaba.dubbo.common.utils.ConfigUtils
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
static
org
.
hongxi
.
whatsmars
.
dubbo
.
starter
.
util
.
DubboUtils
.*;
/**
* Dubbo Config {@link ConfigurationProperties Properties} with prefix "dubbo.config"
*
* @see ConfigurationProperties
*/
@ConfigurationProperties
(
prefix
=
DUBBO_CONFIG_PREFIX
)
public
class
DubboConfigProperties
{
/**
* Indicates multiple properties binding from externalized configuration or not.
*/
private
boolean
multiple
=
DEFAULT_MULTIPLE_CONFIG_PROPERTY_VALUE
;
/**
* Indicates override {@link ConfigUtils#getProperties() Dubbo config properties} from externalized configuration
* or not.
*/
private
boolean
override
=
DEFAULT_OVERRIDE_CONFIG_PROPERTY_VALUE
;
public
boolean
isMultiple
()
{
return
multiple
;
}
public
void
setMultiple
(
boolean
multiple
)
{
this
.
multiple
=
multiple
;
}
public
boolean
isOverride
()
{
return
override
;
}
public
void
setOverride
(
boolean
override
)
{
this
.
override
=
override
;
}
}
whatsmars-dubbo/whatsmars-dubbo-starter/src/main/java/org/hongxi/whatsmars/dubbo/starter/autoconfigure/DubboScanProperties.java
0 → 100644
浏览文件 @
82fcd480
package
org.hongxi.whatsmars.dubbo.starter.autoconfigure
;
import
com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
java.util.LinkedHashSet
;
import
java.util.Set
;
import
static
org
.
hongxi
.
whatsmars
.
dubbo
.
starter
.
util
.
DubboUtils
.
DUBBO_SCAN_PREFIX
;
/**
* Dubbo Scan {@link ConfigurationProperties Properties} with prefix "dubbo.scan"
*
* @see ConfigurationProperties
*/
@ConfigurationProperties
(
prefix
=
DUBBO_SCAN_PREFIX
)
public
class
DubboScanProperties
{
/**
* 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
;
}
}
whatsmars-dubbo/whatsmars-dubbo-starter/src/main/java/org/hongxi/whatsmars/dubbo/starter/autoconfigure/MultipleDubboConfigBindingProperties.java
0 → 100644
浏览文件 @
82fcd480
package
org.hongxi.whatsmars.dubbo.starter.autoconfigure
;
import
com.alibaba.dubbo.config.*
;
import
com.alibaba.dubbo.config.spring.context.annotation.EnableDubboConfig
;
import
com.alibaba.dubbo.config.spring.context.annotation.EnableDubboConfigBinding
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
java.util.LinkedHashMap
;
import
java.util.Map
;
import
static
org
.
hongxi
.
whatsmars
.
dubbo
.
starter
.
util
.
DubboUtils
.
DUBBO_PREFIX
;
/**
* Multiple Dubbo Config Binding{@link ConfigurationProperties Properties} with prefix "dubbo."
*
* @see ConfigurationProperties
* @see EnableDubboConfigBinding
* @see EnableDubboConfig#multiple()
*/
@ConfigurationProperties
(
prefix
=
DUBBO_PREFIX
)
public
class
MultipleDubboConfigBindingProperties
{
/**
* Multiple {@link ApplicationConfig} property
*/
private
Map
<
String
,
ApplicationConfig
>
applications
=
new
LinkedHashMap
<>();
/**
* Multiple {@link ModuleConfig} property
*/
private
Map
<
String
,
ModuleConfig
>
modules
=
new
LinkedHashMap
<>();
/**
* Multiple {@link RegistryConfig} property
*/
private
Map
<
String
,
RegistryConfig
>
registries
=
new
LinkedHashMap
<>();
/**
* Multiple {@link ProtocolConfig} property
*/
private
Map
<
String
,
ProtocolConfig
>
protocols
=
new
LinkedHashMap
<>();
/**
* Multiple {@link MonitorConfig} property
*/
private
Map
<
String
,
MonitorConfig
>
monitors
=
new
LinkedHashMap
<>();
/**
* Multiple {@link ProviderConfig} property
*/
private
Map
<
String
,
ProviderConfig
>
providers
=
new
LinkedHashMap
<>();
/**
* Multiple {@link ConsumerConfig} property
*/
private
Map
<
String
,
ConsumerConfig
>
consumers
=
new
LinkedHashMap
<>();
public
Map
<
String
,
ApplicationConfig
>
getApplications
()
{
return
applications
;
}
public
void
setApplications
(
Map
<
String
,
ApplicationConfig
>
applications
)
{
this
.
applications
=
applications
;
}
public
Map
<
String
,
ModuleConfig
>
getModules
()
{
return
modules
;
}
public
void
setModules
(
Map
<
String
,
ModuleConfig
>
modules
)
{
this
.
modules
=
modules
;
}
public
Map
<
String
,
RegistryConfig
>
getRegistries
()
{
return
registries
;
}
public
void
setRegistries
(
Map
<
String
,
RegistryConfig
>
registries
)
{
this
.
registries
=
registries
;
}
public
Map
<
String
,
ProtocolConfig
>
getProtocols
()
{
return
protocols
;
}
public
void
setProtocols
(
Map
<
String
,
ProtocolConfig
>
protocols
)
{
this
.
protocols
=
protocols
;
}
public
Map
<
String
,
MonitorConfig
>
getMonitors
()
{
return
monitors
;
}
public
void
setMonitors
(
Map
<
String
,
MonitorConfig
>
monitors
)
{
this
.
monitors
=
monitors
;
}
public
Map
<
String
,
ProviderConfig
>
getProviders
()
{
return
providers
;
}
public
void
setProviders
(
Map
<
String
,
ProviderConfig
>
providers
)
{
this
.
providers
=
providers
;
}
public
Map
<
String
,
ConsumerConfig
>
getConsumers
()
{
return
consumers
;
}
public
void
setConsumers
(
Map
<
String
,
ConsumerConfig
>
consumers
)
{
this
.
consumers
=
consumers
;
}
}
whatsmars-dubbo/whatsmars-dubbo-starter/src/main/java/org/hongxi/whatsmars/dubbo/starter/
Dubbo
Properties.java
→
whatsmars-dubbo/whatsmars-dubbo-starter/src/main/java/org/hongxi/whatsmars/dubbo/starter/
autoconfigure/SingleDubboConfigBinding
Properties.java
浏览文件 @
82fcd480
package
org.hongxi.whatsmars.dubbo.starter
;
package
org.hongxi.whatsmars.dubbo.starter.autoconfigure
;
import
com.alibaba.dubbo.config.*
;
import
com.alibaba.dubbo.config.spring.context.annotation.EnableDubboConfigBinding
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.boot.context.properties.NestedConfigurationProperty
;
import
static
org
.
hongxi
.
whatsmars
.
dubbo
.
starter
.
util
.
DubboUtils
.
DUBBO_PREFIX
;
@ConfigurationProperties
(
prefix
=
"spring.dubbo"
)
public
class
DubboProperties
{
private
String
scan
;
/**
* Single Dubbo Config Binding{@link ConfigurationProperties Properties} with prefix "dubbo."
*
* @see ConfigurationProperties
* @see EnableDubboConfigBinding
*/
@ConfigurationProperties
(
prefix
=
DUBBO_PREFIX
)
public
class
SingleDubboConfigBindingProperties
{
/**
* {@link ApplicationConfig} property
*/
@NestedConfigurationProperty
private
ApplicationConfig
application
;
/**
* {@link ModuleConfig} property
*/
@NestedConfigurationProperty
private
ModuleConfig
module
;
/**
* {@link RegistryConfig} property
*/
@NestedConfigurationProperty
private
RegistryConfig
registry
;
/**
* {@link ProtocolConfig} property
*/
@NestedConfigurationProperty
private
ProtocolConfig
protocol
;
/**
* {@link MonitorConfig} property
*/
@NestedConfigurationProperty
private
MonitorConfig
monitor
;
private
ProviderConfig
provider
;
private
ModuleConfig
module
;
private
MethodConfig
method
;
private
ConsumerConfig
consumer
;
public
String
getScan
()
{
return
scan
;
}
/**
* {@link ProviderConfig} property
*/
@NestedConfigurationProperty
private
ProviderConfig
provider
;
public
void
setScan
(
String
scan
)
{
this
.
scan
=
scan
;
}
/**
* {@link ConsumerConfig} property
*/
@NestedConfigurationProperty
private
ConsumerConfig
consumer
;
public
ApplicationConfig
getApplication
()
{
return
application
;
...
...
@@ -40,6 +68,14 @@ public class DubboProperties {
this
.
application
=
application
;
}
public
ModuleConfig
getModule
()
{
return
module
;
}
public
void
setModule
(
ModuleConfig
module
)
{
this
.
module
=
module
;
}
public
RegistryConfig
getRegistry
()
{
return
registry
;
}
...
...
@@ -64,35 +100,20 @@ public class DubboProperties {
this
.
monitor
=
monitor
;
}
public
ProviderConfig
getProvider
()
{
return
provider
;
}
public
void
setProvider
(
ProviderConfig
provider
)
{
this
.
provider
=
provider
;
}
public
ModuleConfig
getModule
()
{
return
module
;
}
public
void
setModule
(
ModuleConfig
module
)
{
this
.
module
=
module
;
}
public
ProviderConfig
getProvider
()
{
return
provider
;
}
public
MethodConfig
getMethod
(
)
{
return
method
;
}
public
void
setProvider
(
ProviderConfig
provider
)
{
this
.
provider
=
provider
;
}
public
void
setMethod
(
MethodConfig
method
)
{
this
.
method
=
method
;
}
public
ConsumerConfig
getConsumer
(
)
{
return
consumer
;
}
public
ConsumerConfig
getConsumer
(
)
{
return
consumer
;
}
public
void
setConsumer
(
ConsumerConfig
consumer
)
{
this
.
consumer
=
consumer
;
}
public
void
setConsumer
(
ConsumerConfig
consumer
)
{
this
.
consumer
=
consumer
;
}
}
whatsmars-dubbo/whatsmars-dubbo-starter/src/main/java/org/hongxi/whatsmars/dubbo/starter/context/event/OverrideDubboConfigApplicationListener.java
0 → 100644
浏览文件 @
82fcd480
package
org.hongxi.whatsmars.dubbo.starter.context.event
;
import
com.alibaba.dubbo.common.utils.ConfigUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent
;
import
org.springframework.context.ApplicationListener
;
import
org.springframework.core.annotation.Order
;
import
org.springframework.core.env.ConfigurableEnvironment
;
import
org.springframework.core.env.Environment
;
import
java.util.SortedMap
;
import
static
org
.
hongxi
.
whatsmars
.
dubbo
.
starter
.
util
.
DubboUtils
.*;
/**
* {@link ApplicationListener} to override the dubbo properties from {@link Environment}into
* {@link ConfigUtils#getProperties() Dubbo Config}.
* {@ConfigUtils Dubbo Config} on {@link ApplicationEnvironmentPreparedEvent}.
* <p>
*
* @see ConfigUtils
*/
@Order
// LOWEST_PRECEDENCE Make sure last execution
public
class
OverrideDubboConfigApplicationListener
implements
ApplicationListener
<
ApplicationEnvironmentPreparedEvent
>
{
@Override
public
void
onApplicationEvent
(
ApplicationEnvironmentPreparedEvent
event
)
{
/**
* Gets Logger After LoggingSystem configuration ready
* @see LoggingApplicationListener
*/
final
Logger
logger
=
LoggerFactory
.
getLogger
(
getClass
());
ConfigurableEnvironment
environment
=
event
.
getEnvironment
();
boolean
override
=
environment
.
getProperty
(
OVERRIDE_CONFIG_PROPERTY_NAME
,
boolean
.
class
,
DEFAULT_OVERRIDE_CONFIG_PROPERTY_VALUE
);
if
(
override
)
{
SortedMap
<
String
,
Object
>
dubboProperties
=
filterDubboProperties
(
environment
);
ConfigUtils
.
getProperties
().
putAll
(
dubboProperties
);
if
(
logger
.
isInfoEnabled
())
{
logger
.
info
(
"Dubbo Config was overridden by externalized configuration {}"
,
dubboProperties
);
}
}
else
{
if
(
logger
.
isInfoEnabled
())
{
logger
.
info
(
"Disable override Dubbo Config caused by property {} = {}"
,
OVERRIDE_CONFIG_PROPERTY_NAME
,
override
);
}
}
}
}
whatsmars-dubbo/whatsmars-dubbo-starter/src/main/java/org/hongxi/whatsmars/dubbo/starter/context/event/WelcomeLogoApplicationListener.java
0 → 100644
浏览文件 @
82fcd480
package
org.hongxi.whatsmars.dubbo.starter.context.event
;
import
com.alibaba.dubbo.common.Version
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent
;
import
org.springframework.boot.logging.LoggingApplicationListener
;
import
org.springframework.context.ApplicationListener
;
import
org.springframework.core.annotation.Order
;
import
static
org
.
hongxi
.
whatsmars
.
dubbo
.
starter
.
util
.
DubboUtils
.*;
import
static
com
.
alibaba
.
dubbo
.
qos
.
server
.
DubboLogo
.
dubbo
;
/**
* Dubbo Welcome Logo {@link ApplicationListener}
*
*/
@Order
(
LoggingApplicationListener
.
DEFAULT_ORDER
+
1
)
public
class
WelcomeLogoApplicationListener
implements
ApplicationListener
<
ApplicationEnvironmentPreparedEvent
>
{
@Override
public
void
onApplicationEvent
(
ApplicationEnvironmentPreparedEvent
event
)
{
/**
* Gets Logger After LoggingSystem configuration ready
* @see LoggingApplicationListener
*/
final
Logger
logger
=
LoggerFactory
.
getLogger
(
getClass
());
String
bannerText
=
buildBannerText
();
if
(
logger
.
isInfoEnabled
())
{
logger
.
info
(
bannerText
);
}
else
{
System
.
out
.
print
(
bannerText
);
}
}
String
buildBannerText
()
{
StringBuilder
bannerTextBuilder
=
new
StringBuilder
();
bannerTextBuilder
.
append
(
LINE_SEPARATOR
)
.
append
(
LINE_SEPARATOR
)
.
append
(
dubbo
)
.
append
(
" :: Dubbo Spring Boot (v"
).
append
(
Version
.
getVersion
(
getClass
(),
"1.0.0"
)).
append
(
") : "
)
.
append
(
DUBBO_SPRING_BOOT_GITHUB_URL
)
.
append
(
LINE_SEPARATOR
)
.
append
(
" :: Dubbo (v"
).
append
(
Version
.
getVersion
()).
append
(
") : "
)
.
append
(
DUBBO_GITHUB_URL
)
.
append
(
LINE_SEPARATOR
)
.
append
(
" :: Google group : "
)
.
append
(
DUBBO_GOOGLE_GROUP_URL
)
.
append
(
LINE_SEPARATOR
)
;
return
bannerTextBuilder
.
toString
();
}
}
whatsmars-dubbo/whatsmars-dubbo-starter/src/main/java/org/hongxi/whatsmars/dubbo/starter/util/DubboUtils.java
0 → 100644
浏览文件 @
82fcd480
package
org.hongxi.whatsmars.dubbo.starter.util
;
import
org.springframework.core.env.ConfigurableEnvironment
;
import
java.util.Collections
;
import
java.util.Map
;
import
java.util.SortedMap
;
import
java.util.TreeMap
;
public
abstract
class
DubboUtils
{
/**
* line separator
*/
public
final
static
String
LINE_SEPARATOR
=
System
.
getProperty
(
"line.separator"
);
/**
* The separator of property name
*/
public
static
final
String
PROPERTY_NAME_SEPARATOR
=
"."
;
/**
* The prefix of property name of Dubbo
*/
public
static
final
String
DUBBO_PREFIX
=
"dubbo"
;
/**
* The prefix of property name for Dubbo scan
*/
public
static
final
String
DUBBO_SCAN_PREFIX
=
DUBBO_PREFIX
+
PROPERTY_NAME_SEPARATOR
+
"scan"
;
/**
* The prefix of property name for Dubbo Config.ØØ
*/
public
static
final
String
DUBBO_CONFIG_PREFIX
=
DUBBO_PREFIX
+
PROPERTY_NAME_SEPARATOR
+
"config"
;
/**
* The property name of base packages to scan
* <p>
* The default value is empty set.
*/
public
static
final
String
BASE_PACKAGES_PROPERTY_NAME
=
DUBBO_SCAN_PREFIX
+
PROPERTY_NAME_SEPARATOR
+
"basePackages"
;
/**
* The property name of multiple properties binding from externalized configuration
* <p>
* The default value is {@link #DEFAULT_MULTIPLE_CONFIG_PROPERTY_VALUE}
*/
public
static
final
String
MULTIPLE_CONFIG_PROPERTY_NAME
=
DUBBO_CONFIG_PREFIX
+
PROPERTY_NAME_SEPARATOR
+
"multiple"
;
/**
* The default value of multiple properties binding from externalized configuration
*/
public
static
final
boolean
DEFAULT_MULTIPLE_CONFIG_PROPERTY_VALUE
=
false
;
/**
* The property name of override Dubbo config
* <p>
* The default value is {@link #DEFAULT_OVERRIDE_CONFIG_PROPERTY_VALUE}
*/
public
static
final
String
OVERRIDE_CONFIG_PROPERTY_NAME
=
DUBBO_CONFIG_PREFIX
+
PROPERTY_NAME_SEPARATOR
+
"override"
;
/**
* The default property value of override Dubbo config
*/
public
static
final
boolean
DEFAULT_OVERRIDE_CONFIG_PROPERTY_VALUE
=
true
;
/**
* The github URL of Dubbo Spring Boot
*/
public
static
final
String
DUBBO_SPRING_BOOT_GITHUB_URL
=
"https://github.com/dubbo/dubbo-spring-boot-project"
;
/**
* The git URL of Dubbo Spring Boot
*/
public
static
final
String
DUBBO_SPRING_BOOT_GIT_URL
=
"https://github.com/dubbo/dubbo-spring-boot-project.git"
;
/**
* The issues of Dubbo Spring Boot
*/
public
static
final
String
DUBBO_SPRING_BOOT_ISSUES_URL
=
"https://github.com/dubbo/dubbo-spring-boot-project/issues"
;
/**
* The github URL of Dubbo
*/
public
static
final
String
DUBBO_GITHUB_URL
=
"https://github.com/alibaba/dubbo"
;
/**
* The google group URL of Dubbo
*/
public
static
final
String
DUBBO_GOOGLE_GROUP_URL
=
"http://groups.google.com/group/dubbo"
;
/**
* Filters Dubbo Properties from {@link ConfigurableEnvironment}
*
* @param environment {@link ConfigurableEnvironment}
* @return Read-only SortedMap
*/
public
static
SortedMap
<
String
,
Object
>
filterDubboProperties
(
ConfigurableEnvironment
environment
)
{
SortedMap
<
String
,
Object
>
dubboProperties
=
new
TreeMap
<>();
Map
<
String
,
Object
>
properties
=
EnvironmentUtils
.
extractProperties
(
environment
);
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
properties
.
entrySet
())
{
String
propertyName
=
entry
.
getKey
();
if
(
propertyName
.
startsWith
(
DUBBO_PREFIX
+
PROPERTY_NAME_SEPARATOR
))
{
dubboProperties
.
put
(
propertyName
,
entry
.
getValue
());
}
}
return
Collections
.
unmodifiableSortedMap
(
dubboProperties
);
}
}
whatsmars-dubbo/whatsmars-dubbo-starter/src/main/java/org/hongxi/whatsmars/dubbo/starter/util/EnvironmentUtils.java
0 → 100644
浏览文件 @
82fcd480
package
org.hongxi.whatsmars.dubbo.starter.util
;
import
org.springframework.core.env.*
;
import
org.springframework.util.ObjectUtils
;
import
java.util.Collections
;
import
java.util.LinkedHashMap
;
import
java.util.Map
;
public
abstract
class
EnvironmentUtils
{
/**
* Extras The properties from {@link ConfigurableEnvironment}
*
* @param environment {@link ConfigurableEnvironment}
* @return Read-only Map
*/
public
static
Map
<
String
,
Object
>
extractProperties
(
ConfigurableEnvironment
environment
)
{
return
Collections
.
unmodifiableMap
(
doExtraProperties
(
environment
));
}
// /**
// * Gets {@link PropertySource} Map , the {@link PropertySource#getName()} as key
// *
// * @param environment {@link ConfigurableEnvironment}
// * @return Read-only Map
// */
// public static Map<String, PropertySource<?>> getPropertySources(ConfigurableEnvironment environment) {
// return Collections.unmodifiableMap(doGetPropertySources(environment));
// }
private
static
Map
<
String
,
Object
>
doExtraProperties
(
ConfigurableEnvironment
environment
)
{
Map
<
String
,
Object
>
properties
=
new
LinkedHashMap
<>();
// orderly
Map
<
String
,
PropertySource
<?>>
map
=
doGetPropertySources
(
environment
);
for
(
PropertySource
<?>
source
:
map
.
values
())
{
if
(
source
instanceof
EnumerablePropertySource
)
{
EnumerablePropertySource
propertySource
=
(
EnumerablePropertySource
)
source
;
String
[]
propertyNames
=
propertySource
.
getPropertyNames
();
if
(
ObjectUtils
.
isEmpty
(
propertyNames
))
{
continue
;
}
for
(
String
propertyName
:
propertyNames
)
{
if
(!
properties
.
containsKey
(
propertyName
))
{
// put If absent
properties
.
put
(
propertyName
,
propertySource
.
getProperty
(
propertyName
));
}
}
}
}
return
properties
;
}
private
static
Map
<
String
,
PropertySource
<?>>
doGetPropertySources
(
ConfigurableEnvironment
environment
)
{
Map
<
String
,
PropertySource
<?>>
map
=
new
LinkedHashMap
<
String
,
PropertySource
<?>>();
MutablePropertySources
sources
=
environment
.
getPropertySources
();
for
(
PropertySource
<?>
source
:
sources
)
{
extract
(
""
,
map
,
source
);
}
return
map
;
}
private
static
void
extract
(
String
root
,
Map
<
String
,
PropertySource
<?>>
map
,
PropertySource
<?>
source
)
{
if
(
source
instanceof
CompositePropertySource
)
{
for
(
PropertySource
<?>
nest
:
((
CompositePropertySource
)
source
)
.
getPropertySources
())
{
extract
(
source
.
getName
()
+
":"
,
map
,
nest
);
}
}
else
{
map
.
put
(
root
+
source
.
getName
(),
source
);
}
}
}
whatsmars-dubbo/whatsmars-dubbo-starter/src/main/resources/META-INF/spring.factories
浏览文件 @
82fcd480
org.springframework.context.ApplicationContextInitializer=\
org.hongxi.whatsmars.dubbo.starter.DubboConfigurationApplicationContextInitializer
org.springframework.context.ApplicationListener=\
org.hongxi.whatsmars.dubbo.starter.DubboHolderListener
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.hongxi.whatsmars.dubbo.starter.DubboAutoConfiguration
\ No newline at end of file
org.hongxi.whatsmars.dubbo.starter.autoconfigure.DubboAutoConfiguration
org.springframework.context.ApplicationListener=\
org.hongxi.whatsmars.dubbo.starter.context.event.OverrideDubboConfigApplicationListener,\
org.hongxi.whatsmars.dubbo.starter.context.event.WelcomeLogoApplicationListener
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录