dubbo通过注解方式暴露服务和引用服务

来源:互联网 发布:linux vi 编辑模式 编辑:程序博客网 时间:2024/05/16 04:29

(一)通过注解方式配置服务暴露,dubbo注解只会在spring bean中被识别

package org.jstudioframework.dubbo.demo.service.impl;import com.alibaba.dubbo.config.annotation.Service;import org.jstudioframework.dubbo.demo.service.ProviderService;import org.springframework.stereotype.Component;/** * 提供者,service实现层 */@Component("providerService")@Service(version="1.0")public class ProviderServiceImpl implements ProviderService {    public String sayHello(String name) {        return "***** OH , My God!~~~~" + name + ",天下无敌,唯我独尊~~~~!!! *****";    }}

Component是Spring bean注解,Service是dubbo的注解(不要和spring bean的service注解弄混)


<!-- 配置dubbo注解识别处理器,不指定包名的话会在spring bean中查找对应实例的类配置了dubbo注解的 --><dubbo:annotation package="org.jstudioframework.dubbo.demo.service"/><!-- 声明需要暴露的服务接口 --><dubbo:service interface="org.jstudioframework.dubbo.demo.service.ProviderService" ref="providerService"/>


二。 注解配置方式引用