2017-05-26 76 views
0

我正在使用Jersey 1.17和CDI(Weld 2.4.1)的Web服務。我在Tomcat8上運行。我的ContextListener和資源類已成功注入我的服務實施,標記爲@Inject。我正在嘗試移動到澤西島2.x,但我遇到了一個障礙。Jersey 1.x to 2.x using CDI

我唯一需要注意的是我的pom.xmlweb.xml

-  <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> 
+  <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class> 
     <init-param> 
-   <param-name>com.sun.jersey.config.property.packages</param-name> 
+   <param-name>jersey.config.server.provider.packages</param-name> 

我的資源類不再被注入儘管我ContextListener是。我看到以下內容:

26-May-2017 12:03:42.596 WARNING [http-nio-8888-exec-2] org.glassfish.jersey.internal.Errors.logErrors The following warnings have been detected: WARNING: Unknown HK2 failure detected: 
MultiException stack 1 of 3 
org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no object available for injection at SystemInjecteeImpl(requiredType=PlatformService,parent=PlatformResource,qualifiers={},position=-1,optional=false,self=false,unqualified=null,379054017) 

我看到焊接記錄表明焊接似乎高興的消息,但我真的很茫然。

2017-05-26 12:03:19,870 [RMI TCP Connection(2)-127.0.0.1] INFO o.j.w.e.servletWeldServlet {} - WELD-ENV-001008: Initialize Weld using ServletContainerInitializer 
2017-05-26 12:03:19,894 [RMI TCP Connection(2)-127.0.0.1] INFO o.j.w.Version {} - WELD-000900: 2.4.1 (Final) 
2017-05-26 12:03:20,173 [RMI TCP Connection(2)-127.0.0.1] INFO o.j.w.Bootstrap {} - WELD-000101: Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously. 
2017-05-26 12:03:20,503 [RMI TCP Connection(2)-127.0.0.1] INFO o.j.w.e.servletTomcat {} - WELD-ENV-001100: Tomcat 7+ detected, CDI injection will be available in Servlets, Filters and Listeners. 
+0

[查看上CDI的支持文檔(https://jersey.github.io/documentation/latest/cdi.support.html) –

+0

你也都出現了異常是不是真的從焊接去,而是來自HK2(你可能知道這不是一個完整的CDI impl)。 – Siliarus

+0

我會進一步指出,hk2並不是一個CDI實現。它可以與CDI一起工作(正如澤西島所做的那樣),但它不是CDI本身 – jwells131313

回答

0

添加此依賴關係似乎解決了該問題。

<dependency> 
    <groupId>org.glassfish.jersey.ext.cdi</groupId> 
    <artifactId>jersey-cdi1x</artifactId> 
    <version>2.23</version> 
</dependency> 
相關問題