diff --git a/README.md b/README.md old mode 100644 new mode 100755 index fb8266c..d691801 --- a/README.md +++ b/README.md @@ -1,30 +1,25 @@ -# spring-boot-starter-dubbo - - -spring-boot-start-dubbo,让你可以使用spring-boot的方式开发dubbo程序。使dubbo开发变得如此简单。 - -让你可以使用`spring-boot`的方式开发`dubbo`程序。使`dubbo`开发变得如此简单。 +#spring-boot-start-dubbo ## 如何使用 -### 1. `clone`代码(可选,已经发布到中央仓库,可以直接依赖[中央仓库的稳定版本](http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22io.dubbo.springboot%22%20AND%20a%3A%22spring-boot-starter-dubbo%22)) +### 1. clone 代码(可选,已经发布到中央仓库,可以直接依赖中央仓库的稳定版本) -```sh +``` git clone git@github.com:teaey/spring-boot-starter-dubbo.git ``` ### 2. 编译安装(可选) -```sh +``` cd spring-boot-starter-dubbo mvn clean install ``` -### 3. 修改`maven`配置文件(可以参考样例[`spring-boot-starter-dubbo-sample`](https://github.com/teaey/spring-boot-starter-dubbo-sample)) -* 在`spring boot`项目的`pom.xml`增加`parent`: +### 3. 修改maven配置文件(可以参考样例[spring-boot-starter-dubbo-sample](https://github.com/teaey/spring-boot-starter-dubbo-sample)) -```xml +* 在Spring Boot项目的pom.xml增加parent: +``` org.springframework.boot spring-boot-starter-parent @@ -32,21 +27,20 @@ mvn clean install ``` -* 在`spring boot`项目的`pom.xml`中添加以下依赖: +* 在Spring Boot项目的pom.xml中添加以下依赖: 根据实际情况依赖最新版本 -```xml +``` - io.dubbo.springboot - spring-boot-starter-dubbo - 1.0.0 + io.dubbo.springboot + spring-boot-starter-dubbo + 1.0.0 ``` -* `maven`插件用于打包成可执行的`uber-jar`文件,添加以下插件(这里一定要加载需要打包成`jar`的`mudule`的`pom`中) - -```xml + * maven插件用于打包成可执行的uber-jar文件,添加以下插件(这里一定要加载需要打包成jar的mudule的pom中) +``` org.springframework.boot spring-boot-maven-plugin @@ -56,9 +50,9 @@ mvn clean install ### 4. 发布服务 -服务接口: +服务接口: -```java +``` package cn.teaey.sprintboot.test; public interface EchoService { @@ -68,9 +62,8 @@ public interface EchoService { ``` -在`application.properties`添加`Dubbo`的版本信息和客户端超时信息,如下: - -```properties +在application.properties添加Dubbo的版本信息和客户端超时信息,如下: +``` spring.dubbo.application.name=provider spring.dubbo.registry.address=zookeeper://192.168.99.100:32770 spring.dubbo.protocol.name=dubbo @@ -79,11 +72,9 @@ spring.dubbo.scan=cn.teaey.sprintboot.test ``` -在`Spring Application`的`application.properties`中添加`spring.dubbo.scan`即可支持`Dubbo`服务发布,其中`scan`表示要扫描的`package`目录。 - -* `spring boot`启动 - -```java +在Spring Application的application.properties中添加spring.dubbo.scan即可支持Dubbo服务发布,其中scan表示要扫描的package目录 +* spring boot启动 +``` package cn.teaey.sprintboot.test; import org.springframework.boot.SpringApplication; @@ -97,10 +88,8 @@ public class Server { } ``` - -* 编写你的`Dubbo`服务,只需要添加要发布的服务实现上添加`@Service`,如下: - -```java +* 编写你的Dubbo服务,只需要添加要发布的服务实现上添加 @Service ,如下 +``` package cn.teaey.sprintboot.test; import com.alibaba.dubbo.config.annotation.Service; @@ -116,21 +105,17 @@ public class EchoServerImpl implements EchoService { ``` -### 5. 消费`Dubbo`服务 - -* 在`application.properties`添加`Dubbo`的版本信息和客户端超时信息,如下: - -```properties +### 5. 消费Dubbo服务 +* 在application.properties添加Dubbo的版本信息和客户端超时信息,如下: +``` spring.dubbo.application.name=consumer spring.dubbo.registry.address=zookeeper://192.168.99.100:32770 spring.dubbo.scan=cn.teaey.sprintboot.test ``` +在Spring Application的application.properties中添加spring.dubbo.scan即可支持Dubbo服务发布,其中scan表示要扫描的package目录 -在`Spring Application`的`application.properties`中添加`spring.dubbo.scan`即可支持`Dubbo`服务发布,其中`scan`表示要扫描的`package`目录。 - -* `spring boot`启动 - -```java +* spring boot启动 +``` package cn.teaey.sprintboot.test; import org.springframework.boot.SpringApplication; @@ -147,10 +132,8 @@ public class Client { } ``` - -* 引用`Dubbo`服务,只需要添加要发布的服务实现上添加`@Reference`,如下: - -```java +* 引用Dubbo服务,只需要添加要发布的服务实现上添加 @Reference ,如下: +``` package cn.teaey.sprintboot.test; import com.alibaba.dubbo.config.annotation.Reference; @@ -163,14 +146,8 @@ public class AbcService { } ``` -### 6. `monitor`监控中心 -* 在`application.properties`添加`monitor`监控中心配置(服务端和消费端相同),如下: - -```properties -spring.dubbo.monitor.protocol=registry -``` +### 6. 打包 -### 7. 打包 +> 可以直接执行Server或者Client启动 -- 可以直接执行`Server`或者`Client`启动 -- 可以通过`mvn clean package`打包成可执行的`uber-jar`文件 +> 可以通过mvn clean package 打包成可执行的uber-jar文件 diff --git a/pom.xml b/pom.xml old mode 100644 new mode 100755 index ff592ff..376f20c --- a/pom.xml +++ b/pom.xml @@ -4,30 +4,29 @@ org.springframework.boot spring-boot-starter-parent - 1.3.6.RELEASE + 2.0.1.RELEASE io.dubbo.springboot spring-boot-starter-dubbo - 1.0.0 + 1.0.1 jar https://github.com/teaey/spring-boot-starter-dubbo spring-boot-starter-dubbo - 1.8 + 1.7 UTF-8 UTF-8 - 1.5.3.RELEASE - 2.5.4-SNAPSHOT - 0.10 - + 2.0.1.RELEASE + 2.6.1 3.5.1 2.2.1 2.9.1 1.5 + @@ -58,7 +57,7 @@ com.101tec zkclient - ${zkclient.version} + 0.7 slf4j-api @@ -74,11 +73,6 @@ - - org.springframework.boot - spring-boot-configuration-processor - true - diff --git a/src/main/java/io/dubbo/springboot/DubboAutoConfiguration.java b/src/main/java/io/dubbo/springboot/DubboAutoConfiguration.java old mode 100644 new mode 100755 index 432d009..31c7f9b --- a/src/main/java/io/dubbo/springboot/DubboAutoConfiguration.java +++ b/src/main/java/io/dubbo/springboot/DubboAutoConfiguration.java @@ -1,12 +1,7 @@ package io.dubbo.springboot; import com.alibaba.dubbo.config.ApplicationConfig; -import com.alibaba.dubbo.config.ConsumerConfig; -import com.alibaba.dubbo.config.MethodConfig; -import com.alibaba.dubbo.config.ModuleConfig; -import com.alibaba.dubbo.config.MonitorConfig; import com.alibaba.dubbo.config.ProtocolConfig; -import com.alibaba.dubbo.config.ProviderConfig; import com.alibaba.dubbo.config.RegistryConfig; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.properties.EnableConfigurationProperties; @@ -17,79 +12,23 @@ @EnableConfigurationProperties(DubboProperties.class) public class DubboAutoConfiguration { - @Autowired - private DubboProperties dubboProperties; + @Autowired + private DubboProperties dubboProperties; - @Bean - public ApplicationConfig requestApplicationConfig() { - ApplicationConfig applicationConfig = dubboProperties.getApplication(); - if (applicationConfig == null) { - applicationConfig = new ApplicationConfig(); - } - return applicationConfig; - } + @Bean + public ApplicationConfig requestApplicationConfig() { + return dubboProperties.getApplication(); + } - @Bean - public RegistryConfig requestRegistryConfig() { - RegistryConfig registryConfig = dubboProperties.getRegistry(); - if (registryConfig == null) { - registryConfig = new RegistryConfig(); - } - return registryConfig; - } + @Bean + public RegistryConfig requestRegistryConfig() { + return dubboProperties.getRegistry(); + } - @Bean - public ProtocolConfig requestProtocolConfig() { - ProtocolConfig protocolConfig = dubboProperties.getProtocol(); - if (protocolConfig == null) { - protocolConfig = new ProtocolConfig(); - } - return protocolConfig; - } + @Bean + public ProtocolConfig requestProtocolConfig() { + return dubboProperties.getProtocol(); + } - @Bean - public MonitorConfig requestMonitorConfig() { - MonitorConfig monitorConfig = dubboProperties.getMonitor(); - if (monitorConfig == null) { - monitorConfig = new MonitorConfig(); - } - return monitorConfig; - } - - @Bean - public ProviderConfig requestProviderConfig() { - ProviderConfig providerConfig = dubboProperties.getProvider(); - if (providerConfig == null) { - providerConfig = new ProviderConfig(); - } - return providerConfig; - } - - @Bean - public ModuleConfig requestModuleConfig() { - ModuleConfig moduleConfig = dubboProperties.getModule(); - if (moduleConfig == null) { - moduleConfig = new ModuleConfig(); - } - return moduleConfig; - } - - @Bean - public MethodConfig requestMethodConfig() { - MethodConfig methodConfig = dubboProperties.getMethod(); - if (methodConfig == null) { - methodConfig = new MethodConfig(); - } - return methodConfig; - } - - @Bean - public ConsumerConfig requestConsumerConfig() { - ConsumerConfig consumerConfig = dubboProperties.getConsumer(); - if (consumerConfig == null) { - consumerConfig = new ConsumerConfig(); - } - return consumerConfig; - } } diff --git a/src/main/java/io/dubbo/springboot/DubboConfigurationApplicationContextInitializer.java b/src/main/java/io/dubbo/springboot/DubboConfigurationApplicationContextInitializer.java old mode 100644 new mode 100755 diff --git a/src/main/java/io/dubbo/springboot/DubboHolderListener.java b/src/main/java/io/dubbo/springboot/DubboHolderListener.java old mode 100644 new mode 100755 index 71adcbc..efa7ef9 --- a/src/main/java/io/dubbo/springboot/DubboHolderListener.java +++ b/src/main/java/io/dubbo/springboot/DubboHolderListener.java @@ -1,7 +1,5 @@ package io.dubbo.springboot; -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; @@ -11,10 +9,7 @@ * @author xiaofei.wxf(teaey) * @since 0.0.0 */ -@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; @@ -27,9 +22,7 @@ public void onApplicationEvent(ApplicationEvent event) { holdThread = new Thread(new Runnable() { @Override public void run() { - if (LOGGER.isTraceEnabled()) { - LOGGER.trace(Thread.currentThread().getName()); - } + System.out.println(Thread.currentThread().getName()); while (running && !Thread.currentThread().isInterrupted()) { try { Thread.sleep(2000); @@ -50,12 +43,4 @@ public void run() { } } } - - public static void stopApplicationContext(Boolean stop){ - running = stop.booleanValue(); - if (null != holdThread) { - holdThread.interrupt(); - holdThread = null; - } - } } diff --git a/src/main/java/io/dubbo/springboot/DubboProperties.java b/src/main/java/io/dubbo/springboot/DubboProperties.java old mode 100644 new mode 100755 index d815341..184a4bd --- a/src/main/java/io/dubbo/springboot/DubboProperties.java +++ b/src/main/java/io/dubbo/springboot/DubboProperties.java @@ -1,12 +1,7 @@ package io.dubbo.springboot; import com.alibaba.dubbo.config.ApplicationConfig; -import com.alibaba.dubbo.config.ConsumerConfig; -import com.alibaba.dubbo.config.MethodConfig; -import com.alibaba.dubbo.config.ModuleConfig; -import com.alibaba.dubbo.config.MonitorConfig; import com.alibaba.dubbo.config.ProtocolConfig; -import com.alibaba.dubbo.config.ProviderConfig; import com.alibaba.dubbo.config.RegistryConfig; import org.springframework.boot.context.properties.ConfigurationProperties; @@ -21,16 +16,6 @@ public class DubboProperties { private ProtocolConfig protocol; - private MonitorConfig monitor; - - private ProviderConfig provider; - - private ModuleConfig module; - - private MethodConfig method; - - private ConsumerConfig consumer; - public String getScan() { return scan; } @@ -63,43 +48,4 @@ 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; - } } diff --git a/src/main/resources/META-INF/spring.factories b/src/main/resources/META-INF/spring.factories old mode 100644 new mode 100755 diff --git a/src/main/resources/META-INF/spring.provides b/src/main/resources/META-INF/spring.provides old mode 100644 new mode 100755