dubbo 服務(wù)在 Tomcat 中啟動的問題

  1. tomcat 管理頁面,reload 或者 stop 服務(wù),然后再 start,服務(wù)就會端口占用。

原因:Tomcat 停止的時(shí)候,沒有釋放掉占用的資源。

解決方法:Tomcat 停止的時(shí)候,執(zhí)行ProtocolConfig.destroyAll();
參考:
https://github.com/alibaba/dubbo/issues/333
web.xml 中配置監(jiān)聽器:


    <listener>
        <listener-class>com.common.listen.InitDeviceListener</listener-class>
    </listener>


@Component
public class InitDeviceListener implements ServletContextListener {
    Logger logger = LoggerFactory.getLogger(InitDeviceListener.class);
    private String rootPath;

    @Override
    public void contextInitialized(ServletContextEvent sce) {
       // tomcat 啟動時(shí)執(zhí)行
        
    }
    
    

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        //tomcat結(jié)束時(shí)執(zhí)行
         ProtocolConfig.destroyAll();
    }
    
}

  1. provider 和 consumer 啟動要有順序。如果 provider 沒有啟動,先啟動 consumer 會報(bào)錯(cuò)。

具體現(xiàn)象:


nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'demoService': FactoryBean threw exception on object creation; 

nested exception is java.lang.IllegalStateException: Failed to check the status of the service com.modules.service.dubbo.DemoService. No provider available for the service …………

原因:
provider 沒有啟動,因此在zookeeper沒有這個(gè)服務(wù),就會報(bào)這個(gè)異常。
解決方法:使用懶加載調(diào)用服務(wù)。


@Lazy
@Autowired
DemoService demoService;

注意:這種方法可以讓 provider 和 consumer 啟動沒有先后順序。但如果 consumer 啟動后,還沒有等 provider 啟動,就調(diào)用了接口,同樣會報(bào)上面的異常。如果在報(bào)錯(cuò)后,再啟動 provider,已經(jīng)不管用了,因?yàn)?consumer 已經(jīng)注入了服務(wù),會報(bào)下面的異常:

org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.modules.service.dubbo.DemoService' available: Optional dependency not present for lazy injection point

因此,比較好的方式是:****不管先后順序,先把兩個(gè)服務(wù)都啟動起來,然后再調(diào)用

  1. provider 中斷,consumer 調(diào)用服務(wù)會報(bào)異常。

具體現(xiàn)象:

com.alibaba.dubbo.rpc.RpcException: Forbid consumer …………

原因:zookeeper發(fā)現(xiàn)相關(guān)服務(wù)接口不存在提供者的時(shí)候,禁用了消費(fèi)者調(diào)用該服務(wù)接口。
參考:http://blog.sina.com.cn/s/blog_4adc4b090102x12u.html

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容

  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 134,915評論 18 139
  • 計(jì)算機(jī)采用二進(jìn)制來表示整數(shù),計(jì)算機(jī)的整數(shù)表示方法有Unsigned Integers 和 Signed Integ...
    要上班的斌哥閱讀 1,580評論 0 2
  • 山水美術(shù)館展出的畢加索展特別好,囊括了畢加索大師的各個(gè)時(shí)期,各種風(fēng)格,各類藝術(shù)形式的作品,加之其好友的攝影作品對他...
    亓盼閱讀 909評論 0 0