我正在使用泽西测试框架,但是,即使在代码进行测试之前,JerseyTest构造函数都会失败:
Mar 06, 2014 6:40:44 PM org.glassfish.jersey.server.ApplicationHandler initialize
INFO: Initiating Jersey application, version Jersey: 2.6 2014-02-18 21:52:53...
A MultiException has 3 exceptions. They are:
1. java.lang.NullPointerException
2. java.lang.IllegalStateException: Unable to perform operation: method inject on com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$App
3. java.lang.IllegalStateException: Unable to perform operation: create on org.glassfish.jersey.message.internal.MessageBodyFactory
MultiException stack 1 of 3
java.lang.NullPointerException
at com.sun.jersey.core.provider.jaxb.AbstractJAXBProvider.setConfiguration(AbstractJAXBProvider.java:112)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.glassfish.hk2.utilities.reflection.ReflectionHelper.invoke(ReflectionHelper.java:1017)
at org.jvnet.hk2.internal.ClazzCreator.methodMe(ClazzCreator.java:375)
at org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:428)
at org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:456)
at org.jvnet.hk2.internal.PerLookupContext.findOrCreate(PerLookupContext.java:69)
at org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2445)
我的测试非常简单:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"/applicationContext-test.xml"})
public class BidAPITest extends JerseyTest {
@Override
protected Application configure() {
return new ResourceConfig(BidAPI.class);
}
@Test
public void testCreate() {
final BidDocument
bid =
target(BidAPI.PATH)
.request()
.post(
Entity.entity("", MediaType.APPLICATION_JSON_TYPE),
BidDocument.class
);
System.out.println(bid);
}
}
在AbstractJaxBprovider中调用SetConfiguration时发生的实际故障发生。在Jettytest构造函数中失败的实际线路是:
public ComponentModelValidator(ServiceLocator locator) {
validators = Lists.newArrayList();
validators.add(new ResourceValidator());
/* -FAILS-> */ validators.add(new RuntimeResourceModelValidator(locator.getService(MessageBodyWorkers.class)));
validators.add(new ResourceMethodValidator(locator));
validators.add(new InvocableValidator());
}
在我开始拆除我的申请之前,有什么想法吗?
谢谢。-ap _
我使用Spring 3.2.6&泽西2.6。我通过将球衣升级到2.9.1。
来解决它。还确保您使用此依赖项使Spring 3&泽西岛共处:
<dependency>
<groupId>org.glassfish.jersey.ext</groupId>
<artifactId>jersey-spring3</artifactId>
<version>2.9.1</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</exclusion>
</exclusions>
</dependency>