这是本人第一次写博客,注册博客园已经有一段时间,由于工作上碰到了一些问题,由此记录一下。

Dubbo的容器模块,是一个独立的容器,因为服务通常不需要Tomcat/JBoss等Web容器的特性,没必要用Web容器去加载服务。

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

一:运行spring容器的方式有三种

1:使用tomcat、jetty等servlet容器运行

2:自己写一个Main方法运行

3:使用dubbo框架提供的Main方法运行

下面是启动dubbo main的代码

  public static void main(String[] args) {
        logger.debug("DubboProvider start...");

        try {
            // 初始化Spring
            @SuppressWarnings("resource")
            ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("commonspring/applicationContext.xml");
            ctx.start();
            logger.error("dubbo provider is running...?>>>>>>>>>>>>>");
             System.in.read();
        } catch (Exception ex) {
            logger.error("dubbo服务提供启动异常!", ex);
        }
     
    }

下面是jar的shell启动脚本
 Dubbo Main启动方式踩坑记录 随笔

上面的dubbo main代码有时候无法后台运行,会出现io异常。所以对dubbo main代码做了优化:

  public static void main(String[] args) {
        logger.debug("DubboProvider start...");

        try {
            // 初始化Spring
            @SuppressWarnings("resource")
            ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("commonspring/applicationContext.xml");
            ctx.start();
            logger.error("dubbo provider is running...?>>>>>>>>>>>>>");
            // System.in.read();
        } catch (Exception ex) {
            logger.error("dubbo服务提供启动异常!", ex);
        }
        synchronized (DubboProvider.class) {
            while (true) {
                try {
                    DubboProvider.class.wait();
                } catch (InterruptedException e) {
                    logger.error("== synchronized error:", e);
                }
            }
        }
    }
以上代码就能运行不出问题。

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄