Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

按照官方demo示例运行消费者调用服务创建bean异常 #4144

Closed
huyihao opened this issue May 23, 2019 · 3 comments
Closed

按照官方demo示例运行消费者调用服务创建bean异常 #4144

huyihao opened this issue May 23, 2019 · 3 comments

Comments

@huyihao
Copy link

huyihao commented May 23, 2019

按照官方demo写了一个生产者工程和消费者工程,生产者注册服务到zk上在dubbo-admin中显示正常,然后起了个消费者工程,消费服务报错
Error creating bean with name 'demoService': FactoryBean threw exception on object creation; nested exception is java.lang.UnsupportedOperationException

Environment

  • Dubbo version: 2.7.1
  • Operating System version: win8.1
  • Java version: JDK1.8
  • Zookeeper version: 3.4.9

code

  1. 生产者
<?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://dubbo.apache.org/schema/dubbo"
    xsi:schemaLocation="
    	http://www.springframework.org/schema/beans        
    	http://www.springframework.org/schema/beans/spring-beans.xsd        
    	http://dubbo.apache.org/schema/dubbo        
    	http://dubbo.apache.org/schema/dubbo/dubbo.xsd">
    	
 	<dubbo:application name="hello-world-app"/>
 	
 	<!--使用 zookeeper 注册中心暴露服务,这里使用不能用client="zkclient"否则会报错,详细原因见:
 		https://github.com/apache/incubator-dubbo/issues/4084
 	 -->
    <dubbo:registry address="zookeeper://127.0.0.1:2181" client="curator" />
    
    <!-- 用dubbo协议在20880端口暴露服务 -->
    <dubbo:protocol name="dubbo" port="20880" />
    
    <!-- 声明需要暴露的服务接口 -->
    <dubbo:service interface="org.apache.dubbo.demo.DemoService" ref="demoService" />
 
    <!-- 和本地bean一样实现服务 -->
    <bean id="demoService" class="org.apache.dubbo.demo.provider.DemoServiceImpl" />         	
</beans>
  1. 消费者
<?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://dubbo.apache.org/schema/dubbo"
    xsi:schemaLocation="
    	http://www.springframework.org/schema/beans        
    	http://www.springframework.org/schema/beans/spring-beans.xsd        
    	http://dubbo.apache.org/schema/dubbo        
    	http://dubbo.apache.org/schema/dubbo/dubbo.xsd">
 	
 	<dubbo:application name="consumer-of-helloworld-app"/>
 	
 	<!--使用 zookeeper 注册中心暴露服务,这里使用不能用client="zkclient"否则会报错,详细原因见:
 		https://github.com/apache/incubator-dubbo/issues/4084
 	 -->
    <dubbo:registry address="zookeeper://127.0.0.1:2181" client="curator" />
    
    <!-- 用dubbo协议在20880端口暴露服务 -->
    <!-- dubbo:protocol name="dubbo" port="20880" /-->
    
    <dubbo:reference id="demoService" interface="org.apache.dubbo.demo.DemoService" check="false"/>
</beans>
  1. 测试代码
public class Consumer {
	public static void main(String[] args) throws Exception {
		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] {
				"classpath*:META-INF/spring/spring-config.xml"
		});
		context.start();
		System.out.println("[consumer] 服务已经启动");
		DemoService demoService = (DemoService) context.getBean("demoService");
		String hello = demoService.sayHello("world");
		System.out.println(hello);
		System.in.read();
	}
}
  1. 报错堆栈信息
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'demoService': FactoryBean threw exception on object creation; nested exception is java.lang.UnsupportedOperationException
	at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:177)
	at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:103)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1640)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:254)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
	at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1080)
	at org.apache.dubbo.demo.init.Consumer.main(Consumer.java:13)
Caused by: java.lang.UnsupportedOperationException
	at java.util.concurrent.CopyOnWriteArrayList$COWIterator.set(CopyOnWriteArrayList.java:1185)
	at java.util.Collections.sort(Collections.java:170)
	at org.apache.dubbo.rpc.cluster.RouterChain.sort(RouterChain.java:87)
	at org.apache.dubbo.rpc.cluster.RouterChain.initWithRouters(RouterChain.java:67)
	at org.apache.dubbo.rpc.cluster.RouterChain.<init>(RouterChain.java:57)
	at org.apache.dubbo.rpc.cluster.RouterChain.buildChain(RouterChain.java:46)
	at org.apache.dubbo.registry.integration.RegistryDirectory.buildRouterChain(RegistryDirectory.java:622)
	at org.apache.dubbo.registry.integration.RegistryProtocol.doRefer(RegistryProtocol.java:385)
	at org.apache.dubbo.registry.integration.RegistryProtocol.refer(RegistryProtocol.java:367)
	at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper.refer(ProtocolFilterWrapper.java:114)
	at org.apache.dubbo.qos.protocol.QosProtocolWrapper.refer(QosProtocolWrapper.java:70)
	at org.apache.dubbo.rpc.protocol.ProtocolListenerWrapper.refer(ProtocolListenerWrapper.java:65)
	at org.apache.dubbo.rpc.Protocol$Adaptive.refer(Protocol$Adaptive.java)
	at org.apache.dubbo.config.ReferenceConfig.createProxy(ReferenceConfig.java:366)
	at org.apache.dubbo.config.ReferenceConfig.init(ReferenceConfig.java:305)
	at org.apache.dubbo.config.ReferenceConfig.get(ReferenceConfig.java:231)
	at org.apache.dubbo.config.spring.ReferenceBean.getObject(ReferenceBean.java:71)
	at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:170)
	... 6 more

Pls. provide [GitHub address] to reproduce this issue.

不知道有没有可能是哪些jar包引用的版本不对,我都是按照官方建议的jar包版本配的

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <apachedubbo.version>2.7.1</apachedubbo.version>
    <zookeeper.version>3.4.9</zookeeper.version>
    <zkclient.version>0.1</zkclient.version>
    <curator.version>2.12.0</curator.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    
	<!-- Apache Dubbo -->
	<dependency>
	    <groupId>org.apache.dubbo</groupId>
	    <artifactId>dubbo</artifactId>
	    <version>${apachedubbo.version}</version>
	</dependency>    
	
	<!-- Dubbo使用zk作为注册中心引入依赖: zookeeper、zkclient -->
	<dependency>
	    <groupId>org.apache.zookeeper</groupId>
	    <artifactId>zookeeper</artifactId>
	    <version>${zookeeper.version}</version>
	</dependency>
	<dependency>
	    <groupId>com.github.sgroschupf</groupId>
	    <artifactId>zkclient</artifactId>
	    <version>${zkclient.version}</version>
	</dependency>	
    
    <!-- 使用Java操作zk需要依赖的包 -->
    <dependency>
	    <groupId>org.apache.curator</groupId>
	    <artifactId>curator-client</artifactId>
	    <version>${curator.version}</version>
	</dependency>
	<dependency>
	    <groupId>org.apache.curator</groupId>
	    <artifactId>curator-framework</artifactId>
	    <version>${curator.version}</version>
	</dependency>	
	<dependency>
	    <groupId>org.apache.curator</groupId>
	    <artifactId>curator-recipes</artifactId>
	    <version>${curator.version}</version>
	</dependency>	
  </dependencies>
@xiehaib
Copy link

xiehaib commented May 24, 2019

I guess, The wrong concurrency container was used in the RouterChain.initWithRouters()method,
or the wrong sort method was used in the RouterChain.sort()method.

Use CopyOnWriteArrayList.sort(Comparator<? super E> c) directly sort instead of use Collections.sort

Waiting for their confirmation.

@Leishunyu
Copy link
Contributor

#3978
The bug has been fixed in 2.7.2

@huyihao
Copy link
Author

huyihao commented May 24, 2019

#3978
The bug has been fixed in 2.7.2

It seems that version 2.7.2 has not been released yet. Which mirror source can I get this version from?

@huyihao huyihao closed this as completed May 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants