三种服务启动模式:
1、 使用web容器(Tomcat、Jetty等)启动dubbo服务 :
增加端口管理复杂性, tomcat/jetty等都需要占用端口,dubbo服务也需要端口;浪费资源(内存),单独启动 tomcat,jetty占用内存大
运用:需要提供web服务的模块,一般dubbo client(侧重服务消费)可以使用这种方式部署
通过Spring容器启动,在spring配置文件加入
<import resource="dubbo-provider.xml" />
配置jetty或tomcat,启动整个项目即可
2、使用自建Main方法类运行spring容器启动dubbo服务:Dobbo提供的优雅停机高级特性没用上,并且自已编写启动类可能会有缺陷
运用:在开发阶段测试dubbo server(侧重服务提供)可以使用这种方式
package dubbo;
import java.io.IOException;
import java.util.concurrent.CountDownLatch;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Provider {
public static void main(String[] args) throws IOException, InterruptedException {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "provider.xml" });
context.start();
CountDownLatch countDownLatch = new CountDownLatch(1);
countDownLatch.await();
}
}
3、使用Dubbo框架提供的Main方法类运行Spring容器启动服务:官方建议使用,dubbo框架本身提供启动类,具备优雅停机高级特性,只需要打成一个可执行jar包的时候指定运行的mainClass是com.alibaba.dubbo.container.Main即可
运用:生产上dubbo server可以用这种方式部署。