- dubbo缺省值会在启动时检测依赖的服务是否可用,不可用时会抛出异常,阻止spring初始化完成,以便能及早发现问题。默认情况下check=true.
- 可以通过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">
<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();
}
}