Dubbo Main啟動方式踩坑記錄


這是本人第一次寫博客,注冊博客園已經有一段時間,由於工作上碰到了一些問題,由此記錄一下。

Dubbo的容器模塊,是一個獨立的容器,因為服務通常不需要Tomcat/JBoss等Web容器的特性,沒必要用Web容器去加載服務。

一:運行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代碼有時候無法后台運行,會出現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);
                }
            }
        }
    }
以上代碼就能運行不出問題。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM