springBoot整合dubbo的好处是可以放弃xml配置,可以使用注解的方式配置dubbo
DubboStarter分两个版本,旧版的io.dubbo.springboot,还有基于Apache的org.apache.dubbo,这里是用的最新版Apache的DubboStarter
pom.xml
4.0.0 test.tomcat start.up1.0-SNAPSHOT 2.3.1.RELEASE org.springframework.boot spring-boot-starter${spring-boot.version} org.apache.dubbo dubbo-spring-boot-starter3.0.4 org.apache.dubbo dubbo-registry-zookeeper3.0.4 org.apache.dubbo dubbo-remoting-zookeeper
application.properties
dubbo.application.name=provider dubbo.registry.address=zookeeper://127.0.0.1:2181 dubbo.protocol.name=dubbo dubbo.protocol.port=20880
暴露的接口
package com.startup.service;
public interface ISayService {
String sayHello();
}
package com.startup.service;
import org.apache.dubbo.config.annotation.DubboService;
@DubboService
public class SayServiceImpl implements ISayService {
public String sayHello() {
return "hello..........";
}
}
直接启动就OK了,先启动Zookeeper
package com.startup;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import java.util.concurrent.CountDownLatch;
@SpringBootApplication
@EnableDubbo(scanbasePackages = {"com.startup.service"})
public class Application {
public static void main(String[] args) throws InterruptedException {
SpringApplication.run(Application.class,args);
System.out.println("dubbo service started");
new CountDownLatch(1).await();
}
}
SpringBoot整合Dubbo超简单 -customer
SpringBoot整合Dubbo超简单 -customer_tfdev的博客-CSDN博客



