- 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();
}
}
- 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)用。
- 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