发布服务
复制代码
1
2
3
4<!-- 和本地服务一样实现远程服务 --> <bean id="xxxService" class="com.xxx.XxxServiceImpl" /> <!-- 增加暴露远程服务配置 --> <dubbo:service interface="com.xxx.XxxService" ref="xxxService" />
ref的值为接口的实现类
引用服务
复制代码
1
2
3
4
5
6<!-- 增加引用远程服务配置 --> <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 就是)
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20<!-- 使用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"/>
复制代码
1
2
3
4<!-- 引用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" />
我的工程
applicationContext-service.xml
springmvc.xml
最后
以上就是落后菠萝最近收集整理的关于dubbo服务的发布的全部内容,更多相关dubbo服务内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复