我正在尝试使用 Spring 托管 bean 插入 Jersey 2.7 资源。具体来说,我想像这样在 Spring bean中注入OAuth1Signature :
@Component
public class OAuthManager {
@Inject
private OAuth1Signature oAuthSignature;
private void someMethod() {
String signature = oAuthSignature.generate(oauthRequest, params, secrets);
}
}
我尝试使用 HK2 Spring 集成文档中提供的说明:HK2 Spring Integration。在文档之后,我将其添加到我的 spring xml 配置中:
<bean class="org.springframework.beans.factory.config.CustomScopeConfigurer">
<property name="scopes">
<map>
<entry key="hk2">
<bean class="org.jvnet.hk2.spring.bridge.api.SpringScopeImpl" >
<property name="ServiceLocatorName" value="HK2ToSpringTest" />
</bean>
</entry>
</map>
</property>
</bean>
<bean id="org.glassfish.jersey.oauth1.signature.OAuth1Signature"
class="org.glassfish.jersey.oauth1.signature.OAuth1Signature"
scope="hk2"
lazy-init="true" />
但是,当我启动我的 web 应用程序时,我不断收到此异常:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.glassfish.hk2.api.ServiceLocator] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:952)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:821)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:735)
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:795)
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:723)
OAuth1Signature 文档指出 ServiceLocator 应该由 Jersey 2.7 使用的 HK2 框架注入。我对如何让 Spring 使用 jersey-spring3 桥为我实例化 OAuth1Signature 感到非常困惑,因为它似乎不知道服务定位器应该来自哪里。
我曾尝试搜索 StackOverflow 和其他 Jersey 留言板,但它们中的大多数都处理相反的用例(在 Jersey 资源中注入 spring bean)。对此的任何帮助将不胜感激!