是否可以部分使用Spring DI和Jersey DI构造对象?
我有一个类JerseyWebService,它使用Jersey DI注入依赖项是否可以部分使用Spring DI和Jersey DI构造对象?,spring,dependency-injection,jersey,jersey-2.0,hk2,Spring,Dependency Injection,Jersey,Jersey 2.0,Hk2,我有一个类JerseyWebService,它使用Jersey DI注入依赖项 @Path("/baskets") public class JerseyWebService { @Inject ExternalApiServiceInterface api; ... } 依赖项在绑定器中指定 public class CustomBinder extends AbstractBinder { @Override protected void confi
@Path("/baskets")
public class JerseyWebService {
@Inject
ExternalApiServiceInterface api;
...
}
依赖项在绑定器中指定
public class CustomBinder extends AbstractBinder {
@Override
protected void configure() {
bind(ExternalApiService.class).to(ExternalApiServiceInterface.class);
...
}
但这里的问题是,ExternalApiService
还有其他依赖项,它使用Spring注入它们
class ExternalApiService implements ExternalApiServiceInterface{
@Autowired
AnotherService aservice;
是否可以在绑定器中只指定Jersey将注入的一些依赖项以及Spring注入的其他依赖项
如果不是,那么如果在ExternalApiService
中是@Inject
而不是@Autowired
,是否必须指定活页夹类中的所有绑定
Jersey DI在找不到任何绑定的情况下是否没有类似于自动连接的特性或委托向Spring注入依赖项 。假设您具有所需的Spring Jersey集成依赖项[1],并且已正确配置应用程序[2]
一,2.
所发生的是(Jersey的DI框架)将为
@Autowired
注释寻找一个新的注释,以解决依赖关系。jersey-spring3
依赖项具有,其中包含对Spring的ApplicationContext
的引用。从这里开始,只需在应用程序上下文中查找它,即可解决依赖关系。如果您使用的是Jersey 2的最新版本,只需将Jersey-spring3库添加到应用程序中,Jersey就可以在不需要自定义绑定的情况下将依赖关系注入您的Spring bean。