大神们耽误1min给瞅瞅什么问题,小妹在此谢过了
1.本地远程调用dubbo接口,用xml实例化bean时报No bean named 'projectInterfaces' is defined
2.我本地的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:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<context:annotation-config/>
<context:component-scan base-package="*"/>
<dubbo:application name="mydubbo"/>
<dubbo:registry address="zookeeper://10.11.145.91:2181?backup=10.11.145.100:2181,10.11.145.103:2181" group=""/>
<dubbo:protocol name="dubbo" port="-1" serialization="" threads="500"/>
<dubbo:reference id="projectInterfaces" interface="com.abc.trade.projectcenter.interfaces.ProjectInterfaces" check="false" timeout="10000" retries="0" group ="test"/>
</beans>
3.我的实例化bean代码
public class TestProject {
public static void main(String[] args) throws Exception {
ApplicationContext context = new ClassPathXmlApplicationContext(
new String[]{"classpath*:spring-config-consumer.xml"});
ProjectInterfaces projectInterfaces = (ProjectInterfaces)context.getBean("projectInterfaces");
Message<List<Project>> msg = projectInterfaces.getProjectsByProductCode("602003162805","200000013631");
List<Project> m = msg.getData();
for (Project project : m){
System.out.println(project.toString());
}
}
}
4.xml中的配置的dubbo:reference id 和interface都是照着其他消费者模块的配置写的(测试环境这些模块都是能正常调用到这个接口的),这个应该没有写错
5.报错是
Dubbo producer needs to be registered in zookeeper before it can be called by cosumer. Check to see if your producer is registered
Your spring-config-consumer.xml file is not loaded by the spring container, so the bean you injected cannot be found in the container.
Context needs to call the start method.
Try it
Look at the code I gave you
When used as follows in the springMVC controller, it will be referenced
That is to say, you need to have an interface, InterfaceService, and there is a class ServiceImpl on the service provider side that implements this interface, and you need to create an object service of this implementation class to provide to consumers. On the provider side, use <bean id="service" class="ServiceImpl" /> to create the provided service, and use ref="service" to indicate that what you want to provide is bean id="service" That object is received on the server side using <dubbo:reference id="service" interface="InterfaceService" />. When used, it is referenced through the common interface type of InterfaceService, so that the service can be obtained and used.
Your problem is that there is no implementation class provided by the service and no object. The ref you specified does not correspond to an actual object. The reference specified by your ref is empty