您的位置:首页 > 其它

dubbox 发布rest服务调用过程记录

2017-08-14 11:14 405 查看
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- 提供方应用信息,用于计算依赖关系 -->
<dubbo:application name="HSFServiceA"/>

<!-- 使用zookeeper统一管理 -->
<dubbo:registry protocol="zookeeper" address="192.168.136.129:2181" />
<!-- 不同协议在不同端口暴露服务 -->
<!-- <dubbo:protocol id="dubbo" name="dubbo" port="31106" accesslog="E:\\logs\\hsf\\hsfserverA.log" /> -->
<dubbo:protocol id="rest" name="rest" port="8080" server="servlet" contextpath="HSFServiceA" accesslog="E:\\logs\\hsf\\hsfserverA.log"/>
<bean id="ServiceAImpl" class="com.services.impl.ServiceAImpl" ></bean>
<dubbo:service interface="com.services.ServiceA" ref="ServiceAImpl" loadbalance="random" timeout="30000" executes="10" >
</dubbo:service>
</beans>

最近在使用dubbox作开发,发布为rest服务,服务起动进使用server=servlet这个模式,但是在调用时怎么也调用不通,所以一直在找原因,上面是服务的xml配置文件,下面是调用者的xml配置文件:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <!-- 消费方应用名,用于计算依赖关系,不是匹配条件,不要与提供方一样 -->
<dubbo:application name="HSFClient" />

<!-- 注册中心地址 -->
<dubbo:registry protocol="zookeeper" address="192.168.136.129:2181" />
<dubbo:protocol id="rest" name="rest" />
<!-- 生成远程服务代理,可以和本地bean一样使用 -->
<dubbo:reference id="ServiceA" interface="com.services.ServiceA" />

</beans>

最后发现是tomcat中server.xml中配置的connector中指定的ip是192.168开头的内部地址,所以通过外网ip获取请求时出错。需要注意的是当使用server=servlet时,port要和外置容器的port一致,而且contextpath要以外置容器的访问路径保持正确的关系,比如我这里是HSFServiceA,那么contextpath要以HSFServiceA开头。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: