Dubbo服务之启动时检测

  1. dubbo缺省值会在启动时检测依赖的服务是否可用,不可用时会抛出异常,阻止spring初始化完成,以便能及早发现问题。默认情况下check=true.
  2. 可以通过ckeck=’false’关闭检查。如下所示关闭check时,启动过程中不报错。在方法调用时报错。
<?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"
    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">

    <!-- 指定web服务名字 -->
    <dubbo:application name="HelloDubbo_ref"/>
    <!-- 声明服务注册中心 -->
    <dubbo:registry protocol="zookeeper" address="127.0.0.1:2181"/>
    <!-- 指定传输层通信协议  因为在同一台机器测试,所以端口不一样-->
    <dubbo:protocol name="dubbo" port="20881"/>
    <!-- 暴露你的服务地址 -->
    <dubbo:reference
        id="dubboFirstService" 
        interface="com.yncp.dubbo.service.IFirstDubboService"
        protocol="dubbo"
        check="false"
    />
 </beans>
package com.yncp.dubbo.service;

import java.io.IOException;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class DubboTest {
    public static void main(String[] args) throws IOException {
        ApplicationContext ctx = new ClassPathXmlApplicationContext(
                "applicationContext.xml");
        IFirstDubboService firstService = (IFirstDubboService) ctx
                .getBean("dubboFirstService");        
        int sum = firstService.add(1, 3);
        System.out.println("1+3等:" + sum);
        int count = firstService.multi(10, 1); 
        System.out.println("10成1等:"+count);
        System.in.read();           
    }

}

这里写图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值