当我尝试从另一个自定义提供程序中引用一个自定义提供程序时,Jersey 会引发异常。
这个测试用例
public class NestedProvidersTest extends JerseyTest {
public NestedProvidersTest() throws TestContainerException {
super(new LowLevelAppDescriptor.Builder(new DefaultResourceConfig(Resource.class, ParentProvider.class, ChildProvider.class)).build());
}
@Test public void test() {
resource().path("/").get(String.class);
}
@Path("/") public static class Resource {
@Context private Parent parent;
@GET public String get() {
return "hello";
}
}
public interface Parent {}
public interface Child {}
@Provider public static class ParentProvider extends PerRequestTypeInjectableProvider<Context, Parent> {
@Context private Child child;
public ParentProvider() {
super(Parent.class);
}
@Override public Injectable<Parent> getInjectable(ComponentContext ic, Context context) {
return new Injectable<Parent>() {
@Override public Parent getValue() {
return new Parent(){};
}
};
}
}
@Provider public static class ChildProvider extends PerRequestTypeInjectableProvider<Context, Child> {
public ChildProvider() {
super(Child.class);
}
@Override public Injectable<Child> getInjectable(ComponentContext ic, Context context) {
return new Injectable<Child>() {
@Override public Child getValue() {
return new Child(){};
}
};
}
}
}
给了我例外
Apr 05, 2013 7:02:41 PM com.sun.jersey.test.framework.spi.container.grizzly2.GrizzlyTestContainerFactory$GrizzlyTestContainer <init>
INFO: Creating low level grizzly2 container configured at the base URI http://localhost:9998/
Apr 05, 2013 7:02:41 PM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
INFO: Initiating Jersey application, version 'Jersey: 1.17.1 02/28/2013 12:47 PM'
Apr 05, 2013 7:02:43 PM com.sun.jersey.spi.inject.Errors processErrorMessages
SEVERE: The following errors and warnings have been detected with resource and/or provider classes:
SEVERE: Missing dependency for field: private NestedProvidersTest$Child NestedProvidersTest$ParentProvider.child
com.sun.jersey.test.framework.spi.container.TestContainerException: com.sun.jersey.spi.inject.Errors$ErrorMessagesException
at com.sun.jersey.test.framework.spi.container.grizzly2.GrizzlyTestContainerFactory$GrizzlyTestContainer.<init>(GrizzlyTestContainerFactory.java:106)
at com.sun.jersey.test.framework.spi.container.grizzly2.GrizzlyTestContainerFactory.create(GrizzlyTestContainerFactory.java:77)
at com.sun.jersey.test.framework.JerseyTest.getContainer(JerseyTest.java:345)
at com.sun.jersey.test.framework.JerseyTest.<init>(JerseyTest.java:220)
at NestedProvidersTest.<init>(NestedProvidersTest.java:22)
[snip]
Caused by: com.sun.jersey.spi.inject.Errors$ErrorMessagesException
at com.sun.jersey.spi.inject.Errors.processErrorMessages(Errors.java:170)
at com.sun.jersey.spi.inject.Errors.postProcess(Errors.java:136)
at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:199)
at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:770)
at com.sun.jersey.api.container.ContainerFactory.createContainer(ContainerFactory.java:172)
at com.sun.jersey.api.container.ContainerFactory.createContainer(ContainerFactory.java:134)
at com.sun.jersey.test.framework.spi.container.grizzly2.GrizzlyTestContainerFactory$GrizzlyTestContainer.<init>(GrizzlyTestContainerFactory.java:102)
... 29 more
我做错了什么,还是泽西岛不支持这种行为?