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

 

<?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开头。

 

最后欢迎大家访问我的个人网站:1024s

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值