我正在将我的系统从 Jersey 1 迁移到 Jersey 2。在我的代码中,我有来自和来自的@Inject
注释。我已将这些更改为and 。com.sun.jersey.spi.inject.Inject
@Singleton
com.sun.jersey.spi.resource.Singleton
javax.inject.Inject
javax.inject.Singleton
由于此更改,我在注入任何用它注释的对象时遇到错误。我的错误是这个
javax.servlet.ServletException: A MultiException has 4 exceptions. They are:
1. org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no object available for injection at SystemInjecteeImpl(requiredType=APIConnectorHandler,parent=BarcodeSearchClient,qualifiers={},position=-1,optional=false,self=false,unqualified=null,1090224052)
2. org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no object available for injection at SystemInjecteeImpl(requiredType=APIConnectorHandler,parent=RSearchClient,qualifiers={},position=-1,optional=false,self=false,unqualified=null,1247004825)
3. java.lang.IllegalArgumentException: While attempting to resolve the dependencies of com.search.barcode.BarcodeSearchClient errors were found
4. java.lang.IllegalStateException: Unable to perform operation: resolve on com.search.barcode.BarcodeSearchClient
org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:423)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:386)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:334)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:221)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
com.filter.MetricsEmittingFilter.doFilter(MetricsEmittingFilter.java:89)
被APIConnectorHandler
注入RSearchClient
和BarcodeSearchClient
。我首先调用了在流程中击中 RSearchClient 的端点,然后调用了 BarcodeSearchClient,因为 RSearchClient 也显示为异常 #2。
我的 web.xml 看起来像这样
<?xml version="1.0"?>
<!--
When modifying this file, DO NOT FORGET to also modify workspace-web.xml
if necessary so that "brazil-build server" will work.
-->
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<context-param>
<description>Spring Expression Language Support</description>
<param-name>springJspExpressionSupport</param-name>
<param-value>false</param-value>
</context-param>
<listener>
<listener-class>com.abc.listener.ContextListener</listener-class>
</listener>
<servlet>
<servlet-name>JerseyServlet</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>
com.search, com.fasterxml.jackson.jaxrs.json
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>JerseyServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<filter-mapping>
<filter-name>MetricsEmittingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
我确实发现了一些 Hk2 无法找到豆子和东西的东西,但我无法理解的是它在 Jersey 1 中是如何工作的。 Jersey 1 是从哪里@Inject
得到豆子的?
PS。这是一个超级遗留代码,我真的不知道为什么,但它具有弹簧集成,但没有一个对象被创建为 bean。它们只是在多个地方用 new 初始化。Spring 仅用于初始化特定于区域的 bean。