Zookeeper - Error : java.lang.IllegalArgumentException: A HostProvider may not be empty!

刚开始学Zookeeper,跟着文档吧集群搭建完,zkCli命令行工具可以正常连接、操作,接下来就想用JavaAPI连接Zookeeper集群,准备就绪,开始运行代码,可以是一直报下面得错误: 

java.lang.IllegalArgumentException: A HostProvider may not be empty!
	at org.apache.zookeeper.client.StaticHostProvider.(StaticHostProvider.java:88)
	at org.apache.zookeeper.ZooKeeper.(ZooKeeper.java:449)
	at org.apache.zookeeper.ZooKeeper.(ZooKeeper.java:383)
	at demo.javaapi2.ZookeeperConstructorUsageSimple.getConnection(ZookeeperConstructorUsageSimple.java:21)
	at demo.javaapi2.ZookeeperConstructorUsageSimpleTest.testConnection(ZookeeperConstructorUsageSimpleTest.java:21)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
	at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
	at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

因为是初学者,看到错误,就是网上各种搜,但都没人碰到和我一样问题,于是debug了一下,发现是Host Connection String参数为空,因为我用得是spring test做unit test得,忘记在spring xml文件中配置

 

配置文件的位置,导致

@Value("${zk.cluster.server.host}")
private String CONNECTION;

获取到得Connection值为空,所以一直报以上错误。再回头一看报得Error,才恍然大悟。

 

你可能感兴趣的:(Zookeeper)