学习dubbo项目架构时,consumer 报错class not found

使用测试类方式启动dubbo  指定此项目为a项目

一、ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("dubbo-provider.xml");

context.start();
<!-- 声明需要暴露的服务接口 -->
<dubbo:service interface="com.zd.service.DemoService" ref="demoService" />

<!-- 和本地bean一样实现服务 -->
<bean id="demoService" class="com.zd.service.impl.DemoServiceImpl" />

这时候项目有两种功能情况:
1、 <dubbo:service interface="com.zd.service.DemoService" ref="demoService" />
这里interface 指定的接口可以是a项目本身,也可以是b项目(b项目仅仅是一个普通的java项目,a项目中加入了b项目的依赖)
使用配置类是可以直接 这样获取interface ,就算这个interface在其他java项目中还是能顾拿到
2、如果使用web.xml 方式启动的话,如果该接口没有注入到Spring中,那么就会报错,报can not found class exception
因为通过b项目区获取这个接口,xml会去ioc容器中去找,而a项目中的这个接口仅仅是一个普通的java项目接口,没有注入到ioc中。


猜你喜欢

转载自www.cnblogs.com/enzoluo-blog/p/9300254.html