dubbo服务的发布

发布服务

<!-- 和本地服务一样实现远程服务 -->
<bean id="xxxService" class="com.xxx.XxxServiceImpl" />
<!-- 增加暴露远程服务配置 -->
<dubbo:service interface="com.xxx.XxxService" ref="xxxService" />

ref的值为接口的实现类

引用服务

<!-- 增加引用远程服务配置 -->
<dubbo:reference id="xxxService" interface="com.xxx.XxxService" />
<!-- 和本地服务一样使用远程服务 -->
<bean id="xxxAction" class="com.xxx.XxxAction">
	<property name="xxxService" ref="xxxService" />
</bean>

这里reference标签里的id就是实现类的bean id


完整配置

以上是发布和调用的简单配置,真正配置中还需要注册中心的端口号和ip

下面是用zookeeper做为注册中心的dubbo发布和调用的完整配置

(不知道虚拟机ip的小伙伴打开终端输入ifconfig 里面的inet addr 就是)

<!-- 使用dubbo发布服务 -->
	
	<!-- 提供方应用信息,用于计算依赖关系 -->
	<dubbo:application name="art-manager" />
	<dubbo:registry protocol="zookeeper"
		address="192.168.2.100:2181" />
	<!-- 用dubbo协议在20880端口暴露服务 -->
	<dubbo:protocol name="dubbo" port="20880" />
	<!-- 声明需要暴露的服务接口 -->
	
    <!--  手动配置bean-->
	<!--<bean id="itemService" class="com.art.service.impl.ItemServiceImpl"/> -->
     <dubbo:service interface="com.art.service.ItemService" ref="itemService" 
     timeout="300000"/>    

 
     <!-- 如果不想手动配置的bean就ref接口的实现类首字母小写,因为Spring会将@Service注解下的类创建
      bean实例,名称是类名首字母小写-->
     <dubbo:service interface="com.art.service.ItemService" ref="itemServiceImpl" 
     timeout="300000"/>
    <!-- 引用dubbo服务 -->
	<dubbo:application name="art-manager-web"/>
	<dubbo:registry protocol="zookeeper" address="192.168.2.100:2181"/>	
	<dubbo:reference interface="com.art.service.ItemService" id="itemService" />

我的工程

扫描二维码关注公众号,回复: 2466503 查看本文章

applicationContext-service.xml

springmvc.xml

猜你喜欢

转载自blog.csdn.net/weixin_38497513/article/details/81212769