springboot + dubbo2.6.1 + zookeeper
提供者已成功注册到 zookeeper,从dubbo管理端可以浏览到
说明提供者已注册成功。
消费者使用 配置文件
consumer.xml
<?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"
xmlns:p="http://www.springframework.org/schema/p"
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="hello-world-app-client" />
<dubbo:registry address="zookeeper://127.0.0.1:2181" />
<dubbo:annotation package="mydubbo.app.dubbo" />
</beans>
@ImportResource(value = {"classpath:consumer.xml"})
@DubboComponentScan(basePackages = "mydubbo.app.dubbo")
@SpringBootApplication
public class MydubboclientApplication {
@Reference( version="1.0.0")
static helloWorld call;
public static void main(String[] args) {
ConfigurableApplicationContext ctx = SpringApplication.run(MydubboclientApplication.class, args);
call.getCityName("test");
}
}
提示:
Exception in thread "main" java.lang.NullPointerException
at mydubbo.app.MydubboclientApplication.main(MydubboclientApplication.java:24)
@Reference注解的为 null
使用xml中配置bean
<bean id="demoServiceRemote" class="mydubbo.app.dubbo.impl.helloWorldImpl"></bean>
在启动时使用下面调用方式
helloWorld call = (helloWorld)ctx.getBean("demoServiceRemote");
call.getCityName("test");
则报异常。无法生成bean.