2016-01-22 137 views
1

我想設置一個基於澤西島2的REST客戶端。該客戶端代碼需要在Jetty 9服務器(獨立,不嵌入)中運行,並應該從其他服務檢索/使用數據。 我非常基本的測試呼叫看起來是這樣的:澤西島客戶端:hk2 UnsatisfiedDependencyException

ClientBuilder.newClient().target("https://10.224.1.206:8443/axis/services/EndSystemWebService").path("getAll").request().get(String.class) 

此調用失敗,出現以下錯誤:

Exception in thread "MyApp" MultiException stack 1 of 1 org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no object available for injection at SystemInjecteeImpl(requiredType=ServiceLocator,parent=JaxbAutoDiscoverable,qualifiers={},position=-1,optional=false,self=false,unqualified=null,186516043) at org.jvnet.hk2.internal.ThreeThirtyResolver.resolve(ThreeThirtyResolver.java:75) at org.jvnet.hk2.internal.Utilities.justInject(Utilities.java:945) at org.jvnet.hk2.internal.ServiceLocatorImpl.inject(ServiceLocatorImpl.java:980) at org.jvnet.hk2.internal.ServiceLocatorImpl.createAndInitialize(ServiceLocatorImpl.java:1055) at org.jvnet.hk2.internal.ServiceLocatorImpl.createAndInitialize(ServiceLocatorImpl.java:1046) at org.glassfish.jersey.model.internal.CommonConfig.configureAutoDiscoverableProviders(CommonConfig.java:608) at org.glassfish.jersey.client.ClientConfig$State.configureAutoDiscoverableProviders(ClientConfig.java:364) at org.glassfish.jersey.client.ClientConfig$State.initRuntime(ClientConfig.java:399) at org.glassfish.jersey.client.ClientConfig$State.access$000(ClientConfig.java:90) at org.glassfish.jersey.client.ClientConfig$State$3.get(ClientConfig.java:122) at org.glassfish.jersey.client.ClientConfig$State$3.get(ClientConfig.java:119) at org.glassfish.jersey.internal.util.collection.Values$LazyValueImpl.get(Values.java:340) at org.glassfish.jersey.client.ClientConfig.getRuntime(ClientConfig.java:733) at org.glassfish.jersey.client.ClientRequest.getConfiguration(ClientRequest.java:285) at org.glassfish.jersey.client.JerseyInvocation.validateHttpMethodAndEntity(JerseyInvocation.java:135) at org.glassfish.jersey.client.JerseyInvocation.(JerseyInvocation.java:105) at org.glassfish.jersey.client.JerseyInvocation.(JerseyInvocation.java:101) at org.glassfish.jersey.client.JerseyInvocation.(JerseyInvocation.java:92) at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:420) at org.glassfish.jersey.client.JerseyInvocation$Builder.get(JerseyInvocation.java:316)

我沒有設置使用Maven我的環境中 - 做手工。所以也許我正在使用的庫有些問題。在這裏,他們是:

enter image description here

這些是太多的現在,但我一直將它們設爲我希望這一問題將僅僅是因爲缺少一個罐子。事實並非如此。

任何幫助,高度讚賞。謝謝

+1

** 1。**錯誤與您提供的罐子圖像不匹配。有錯誤是說ServiceLocator不能被注入到JaxbAutoDiscoverable中。你的圖片甚至不會顯示該類所在的jersey-media-jaxb jar。** 2。**你的jar版本與發佈版本不匹配,所以我不知道在哪裏你從中得到它們。具體來說,在Jersey 2.22.1發行版中的HK2版本應該是2.4.0-b031 –

+1

** 3。嘗試並下載實際的[distribution(ri-bundle)](https://jersey.java。 net/download.html),如果您只需要客戶端,請查看[此帖子](http://stackoverflow.com/a/34793820/2587435)獲取所需的最小瓶子。 –

+0

感謝您的快速幫助!我刪除了與球衣相關的所有罐子,下載了你指向我的官方捆綁包,並用它們代替。現在工作! – Kurt

回答

2

感謝來自peeskillet的意見,我從jersey下載了捆綁包,刪除了之前添加到我的項目中的所有罐子,將所需的罐子添加到捆綁包中(以避免不兼容),並且錯誤消失了。再次感謝!