0
我正在使用Jersey 1.17和CDI(Weld 2.4.1)的Web服务。我在Tomcat8上运行。我的ContextListener
和资源类已成功注入我的服务实施,标记为@Inject
。我正在尝试移动到泽西岛2.x,但我遇到了一个障碍。Jersey 1.x to 2.x using CDI
我唯一需要注意的是我的pom.xml
和web.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.
[查看上CDI的支持文档(https://jersey.github.io/documentation/latest/cdi.support.html) –
你也都出现了异常是不是真的从焊接去,而是来自HK2(你可能知道这不是一个完整的CDI impl)。 – Siliarus
我会进一步指出,hk2并不是一个CDI实现。它可以与CDI一起工作(正如泽西岛所做的那样),但它不是CDI本身 – jwells131313