Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
武汉红喜
whatsmars
提交
1df8fc81
W
whatsmars
项目概览
武汉红喜
/
whatsmars
通知
3
Star
0
Fork
1
代码
文件
提交
分支
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,体验更适合开发者的 AI 搜索 >>
提交
1df8fc81
编写于
1月 15, 2018
作者:
武汉红喜
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
简单实现 spring-boot-starter-dubbo
上级
f9ec6e37
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
345 addition
and
34 deletion
+345
-34
whatsmars-dubbo/pom.xml
whatsmars-dubbo/pom.xml
+1
-0
whatsmars-dubbo/whatsmars-dubbo-consumer-boot/pom.xml
whatsmars-dubbo/whatsmars-dubbo-consumer-boot/pom.xml
+3
-15
whatsmars-dubbo/whatsmars-dubbo-consumer-boot/src/main/java/org/hongxi/whatsmars/dubbo/demo/consumer/ConsumerApplication.java
...xi/whatsmars/dubbo/demo/consumer/ConsumerApplication.java
+2
-2
whatsmars-dubbo/whatsmars-dubbo-consumer-boot/src/main/resources/application.yml
...rs-dubbo-consumer-boot/src/main/resources/application.yml
+2
-0
whatsmars-dubbo/whatsmars-dubbo-provider-boot/pom.xml
whatsmars-dubbo/whatsmars-dubbo-provider-boot/pom.xml
+3
-15
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
-2
whatsmars-dubbo/whatsmars-dubbo-provider-boot/src/main/resources/application.yml
...rs-dubbo-provider-boot/src/main/resources/application.yml
+2
-0
whatsmars-dubbo/whatsmars-dubbo-starter/pom.xml
whatsmars-dubbo/whatsmars-dubbo-starter/pom.xml
+53
-0
whatsmars-dubbo/whatsmars-dubbo-starter/src/main/java/org/hongxi/whatsmars/dubbo/starter/DubboAutoConfiguration.java
...ongxi/whatsmars/dubbo/starter/DubboAutoConfiguration.java
+88
-0
whatsmars-dubbo/whatsmars-dubbo-starter/src/main/java/org/hongxi/whatsmars/dubbo/starter/DubboConfigurationApplicationContextInitializer.java
...rter/DubboConfigurationApplicationContextInitializer.java
+27
-0
whatsmars-dubbo/whatsmars-dubbo-starter/src/main/java/org/hongxi/whatsmars/dubbo/starter/DubboHolderListener.java
...g/hongxi/whatsmars/dubbo/starter/DubboHolderListener.java
+57
-0
whatsmars-dubbo/whatsmars-dubbo-starter/src/main/java/org/hongxi/whatsmars/dubbo/starter/DubboProperties.java
...a/org/hongxi/whatsmars/dubbo/starter/DubboProperties.java
+98
-0
whatsmars-dubbo/whatsmars-dubbo-starter/src/main/resources/META-INF/spring.factories
...ubbo-starter/src/main/resources/META-INF/spring.factories
+6
-0
whatsmars-dubbo/whatsmars-dubbo-starter/src/main/resources/META-INF/spring.provides
...dubbo-starter/src/main/resources/META-INF/spring.provides
+1
-0
未找到文件。
whatsmars-dubbo/pom.xml
浏览文件 @
1df8fc81
...
...
@@ -21,6 +21,7 @@
<module>
whatsmars-dubbo-provider-boot
</module>
<module>
whatsmars-dubbo-consumer-boot
</module>
<module>
whatsmars-dubbo-service
</module>
<module>
whatsmars-dubbo-starter
</module>
</modules>
...
...
whatsmars-dubbo/whatsmars-dubbo-consumer-boot/pom.xml
浏览文件 @
1df8fc81
...
...
@@ -15,7 +15,7 @@
<properties>
<!-- The main class to start by executing java -jar -->
<start-class>
org.hongxi.whatsmars.dubbo.demo.consumer.
App
</start-class>
<start-class>
org.hongxi.whatsmars.dubbo.demo.consumer.
ConsumerApplication
</start-class>
</properties>
<dependencyManagement>
...
...
@@ -32,21 +32,9 @@
<dependencies>
<dependency>
<groupId>
io.dubbo.springboot
</groupId>
<groupId>
org.hongxi
</groupId>
<artifactId>
spring-boot-starter-dubbo
</artifactId>
<version>
1.0.0
</version>
<exclusions>
<!-- bad idea -->
<exclusion>
<groupId>
com.alibaba
</groupId>
<artifactId>
dubbo
</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- bad idea, just for using the latest version -->
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
dubbo
</artifactId>
<version>
${dubbo.version}
</version>
<version>
1.0-SNAPSHOT
</version>
</dependency>
<dependency>
<groupId>
org.hongxi
</groupId>
...
...
whatsmars-dubbo/whatsmars-dubbo-consumer-boot/src/main/java/org/hongxi/whatsmars/dubbo/demo/consumer/
App
.java
→
whatsmars-dubbo/whatsmars-dubbo-consumer-boot/src/main/java/org/hongxi/whatsmars/dubbo/demo/consumer/
ConsumerApplication
.java
浏览文件 @
1df8fc81
...
...
@@ -9,9 +9,9 @@ import org.springframework.context.ConfigurableApplicationContext;
* Created by javahongxi on 2017/12/4.
*/
@SpringBootApplication
public
class
App
{
public
class
ConsumerApplication
{
public
static
void
main
(
String
[]
args
)
{
ConfigurableApplicationContext
context
=
SpringApplication
.
run
(
App
.
class
,
args
);
ConfigurableApplicationContext
context
=
SpringApplication
.
run
(
ConsumerApplication
.
class
,
args
);
DemoRpc
demoRpc
=
context
.
getBean
(
DemoRpc
.
class
);
System
.
out
.
println
(
demoRpc
.
sayHello
(
"Lily"
));
}
...
...
whatsmars-dubbo/whatsmars-dubbo-consumer-boot/src/main/resources/application.yml
浏览文件 @
1df8fc81
...
...
@@ -4,4 +4,6 @@ spring:
name
:
demo-consumer
registry
:
address
:
zookeeper://127.0.0.1:2181
module
:
name
:
demo
scan
:
org.hongxi.whatsmars.dubbo.demo.consumer.rpc
\ No newline at end of file
whatsmars-dubbo/whatsmars-dubbo-provider-boot/pom.xml
浏览文件 @
1df8fc81
...
...
@@ -15,7 +15,7 @@
<properties>
<!-- The main class to start by executing java -jar -->
<start-class>
org.hongxi.whatsmars.dubbo.demo.provider.
App
</start-class>
<start-class>
org.hongxi.whatsmars.dubbo.demo.provider.
ProviderApplication
</start-class>
</properties>
<dependencyManagement>
...
...
@@ -32,21 +32,9 @@
<dependencies>
<dependency>
<groupId>
io.dubbo.springboot
</groupId>
<groupId>
org.hongxi
</groupId>
<artifactId>
spring-boot-starter-dubbo
</artifactId>
<version>
1.0.0
</version>
<exclusions>
<!-- bad idea -->
<exclusion>
<groupId>
com.alibaba
</groupId>
<artifactId>
dubbo
</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- bad idea, just for using the latest version -->
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
dubbo
</artifactId>
<version>
${dubbo.version}
</version>
<version>
1.0-SNAPSHOT
</version>
</dependency>
<dependency>
<groupId>
org.hongxi
</groupId>
...
...
whatsmars-dubbo/whatsmars-dubbo-provider-boot/src/main/java/org/hongxi/whatsmars/dubbo/demo/provider/
App
.java
→
whatsmars-dubbo/whatsmars-dubbo-provider-boot/src/main/java/org/hongxi/whatsmars/dubbo/demo/provider/
ProviderApplication
.java
浏览文件 @
1df8fc81
...
...
@@ -9,8 +9,8 @@ import org.springframework.context.annotation.ComponentScan;
*/
@SpringBootApplication
@ComponentScan
(
value
=
{
"org.hongxi.whatsmars.dubbo"
})
public
class
App
{
public
class
ProviderApplication
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
App
.
class
,
args
);
SpringApplication
.
run
(
ProviderApplication
.
class
,
args
);
}
}
whatsmars-dubbo/whatsmars-dubbo-provider-boot/src/main/resources/application.yml
浏览文件 @
1df8fc81
...
...
@@ -7,4 +7,6 @@ spring:
protocol
:
name
:
dubbo
port
:
20881
module
:
name
:
demo
scan
:
org.hongxi.whatsmars.dubbo.demo.provider.resource
\ No newline at end of file
whatsmars-dubbo/whatsmars-dubbo-starter/pom.xml
0 → 100644
浏览文件 @
1df8fc81
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<parent>
<artifactId>
whatsmars-dubbo
</artifactId>
<groupId>
org.hongxi
</groupId>
<version>
1.0-SNAPSHOT
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
spring-boot-starter-dubbo
</artifactId>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-dependencies
</artifactId>
<version>
${spring-boot.version}
</version>
<type>
pom
</type>
<scope>
import
</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter
</artifactId>
</dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
dubbo
</artifactId>
<version>
${dubbo.version}
</version>
<exclusions>
<exclusion>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-beans
</artifactId>
</exclusion>
<exclusion>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-context
</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>
com.101tec
</groupId>
<artifactId>
zkclient
</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
whatsmars-dubbo/whatsmars-dubbo-starter/src/main/java/org/hongxi/whatsmars/dubbo/starter/DubboAutoConfiguration.java
0 → 100644
浏览文件 @
1df8fc81
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
0 → 100644
浏览文件 @
1df8fc81
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
;
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
0 → 100644
浏览文件 @
1df8fc81
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/DubboProperties.java
0 → 100644
浏览文件 @
1df8fc81
package
org.hongxi.whatsmars.dubbo.starter
;
import
com.alibaba.dubbo.config.*
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
@ConfigurationProperties
(
prefix
=
"spring.dubbo"
)
public
class
DubboProperties
{
private
String
scan
;
private
ApplicationConfig
application
;
private
RegistryConfig
registry
;
private
ProtocolConfig
protocol
;
private
MonitorConfig
monitor
;
private
ProviderConfig
provider
;
private
ModuleConfig
module
;
private
MethodConfig
method
;
private
ConsumerConfig
consumer
;
public
String
getScan
()
{
return
scan
;
}
public
void
setScan
(
String
scan
)
{
this
.
scan
=
scan
;
}
public
ApplicationConfig
getApplication
()
{
return
application
;
}
public
void
setApplication
(
ApplicationConfig
application
)
{
this
.
application
=
application
;
}
public
RegistryConfig
getRegistry
()
{
return
registry
;
}
public
void
setRegistry
(
RegistryConfig
registry
)
{
this
.
registry
=
registry
;
}
public
ProtocolConfig
getProtocol
()
{
return
protocol
;
}
public
void
setProtocol
(
ProtocolConfig
protocol
)
{
this
.
protocol
=
protocol
;
}
public
MonitorConfig
getMonitor
()
{
return
monitor
;
}
public
void
setMonitor
(
MonitorConfig
monitor
)
{
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
MethodConfig
getMethod
()
{
return
method
;
}
public
void
setMethod
(
MethodConfig
method
)
{
this
.
method
=
method
;
}
public
ConsumerConfig
getConsumer
()
{
return
consumer
;
}
public
void
setConsumer
(
ConsumerConfig
consumer
)
{
this
.
consumer
=
consumer
;
}
}
whatsmars-dubbo/whatsmars-dubbo-starter/src/main/resources/META-INF/spring.factories
0 → 100644
浏览文件 @
1df8fc81
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
whatsmars-dubbo/whatsmars-dubbo-starter/src/main/resources/META-INF/spring.provides
0 → 100644
浏览文件 @
1df8fc81
provides: spring-boot-starter-dubbo
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录