我们已经实现了一个框架,它使用带有自定义注释的hk2来在我们的rest服务类中注入对象。现在,如果注释以注入方式存在于注入对象内,我们也希望注入对象。用hk2有一个干净的方法吗?或者我必须使用另一个图书馆?在这种情况下,哪个库可以解决这个任务(我们需要一个尽可能轻的库)? 谢谢你的回复
更新
我们实施的框架与@peeskillet在此post中解释的框架非常相似。 按照我的需要解释:
例如,我有一个使用 @myCustomAnnotation 的服务:
@Path("/test")
public class RestService implements IRestService {
@myCustomAnnotation
private TestObject object;
@GET
@Path("/myTestObject")
public TestObject getMyObject(){
return object;
}
}
一切正常。
我的问题是:
如果我进入 TestObject 类定义,则使用 @myCustomAnnotation 的另一个对象,例如:
public class TestObject {
@myCustomAnnotation
private AnotherObject object;
public AnotherObject getObject(){
return object;
}
}
未注入,因此 AnotherObject 对象始终为null。
我已经在 InjectionResolver 的resolve方法中解决了2种对象:
public Object resolve(Injectee injectee, ServiceHandle<?> handle) {
Object result=null;
if (TestObject.class == injectee.getRequiredType()) {
result = systemInjectionResolver.resolve(injectee, handle);
} else if (AnotherObject.class == injectee.getRequiredType()) {
result = systemInjectionResolver.resolve(injectee, handle);
}
return result;
}
我希望我很清楚。