springboot--application.yml集成dubbo

Service层:
1.pom里面引jar包

		
		
			com.101tec
			zkclient
			${zkclient.version}
		
		
			com.alibaba.spring.boot
			dubbo-spring-boot-starter
			2.0.0
		
		

2.application.yml配置文件
这是最简单的配置了,更多详细配置可以随着需要添加

  dubbo:
    server: true
    registry:
      address: zookeeper://192.168.25.133:2181
    protocol:
      name: dubbo
      port: 20899
    scan: com.lbonline
    provider:
      filter: catTransaction

web层
1.pom文件

        
        
            com.101tec
            zkclient
            ${zkclient.version}
        
        
            com.alibaba.spring.boot
            dubbo-spring-boot-starter
            ${dubbo.version}
        
        

2.application.yml配置文件

dubbo:
    registry:
       address: zookeeper://192.168.25.133:2181
    protocol:
      name: dubbo
      port: 20899
    scan: com.lbonline
    consumer:
      filter: catTransaction
      check: false

配置好了接下来一个调用的小例子,用的是scan扫描接下来注解得需要注意了

import com.alibaba.dubbo.config.annotation.Reference;
/**
 * @Auther: lijianmin
 * @Date: 2018/8/11 15:02
 * @Description:
 */
@Api(value = "评论信息拉取", tags = "评论信息拉取")
@RestController
@RequestMapping("/api/comment/")
@Slf4j
public class CommentController {

    @Reference(version ="1.0.0")
    CommentServer commentServer;
    @ApiOperation(value = "查询课程评论")
    @GetMapping("/schedule")
    public ResultVo findComment(@RequestParam("scheduleId") Integer scheduleId, @RequestParam("beginTime") String beginTime){
        Comment comment = commentServer.findCommentBysIdBtime(scheduleId, beginTime);
        return ResultVoUtil.success(comment);
    }
}

需要注意的是@reference的包import com.alibaba.dubbo.config.annotation.Reference;

import com.alibaba.dubbo.config.annotation.Service;
/**
 * @Auther: lijianmin
 * @Date: 2018/8/11 15:02
 * @Description:
 */
@Service(version = "1.0.0", interfaceClass = CommentServer.class, timeout = 3000)
@Component
@Slf4j
public class CommentServerImpl implements CommentServer {
    @Autowired
    CommentMapper commentMapper;
    @Override
    public Comment findComment(int classId) {
        return commentMapper.findComment(classId);
    }

    /**
     * 根据课程id和课程开始时间查询评价
     * @param scheduleId
     * @param beginTiome
     * @return
     */
    @Override
    public Comment findCommentBysIdBtime(int scheduleId, String beginTiome) {
        return commentMapper.findCommentBysIdBtime(scheduleId,beginTiome);
    }
}

需要注意的是这个@service的注解的引用包import com.alibaba.dubbo.config.annotation.Service;

最简单的一个整合就到了,详细的可以查看官网

你可能感兴趣的:(springboot)