使用Jersey测试框架在Jersey测试构造函数期间生成NullPointerException
我正在使用Jersey测试框架,但是,即使在代码进入我的测试之前,Jersey测试构造函数也会失败:使用Jersey测试框架在Jersey测试构造函数期间生成NullPointerException,exception,pointers,testing,null,jersey,Exception,Pointers,Testing,Null,Jersey,我正在使用Jersey测试框架,但是,即使在代码进入我的测试之前,Jersey测试构造函数也会失败: 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.
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());
}
在我开始破解我的应用程序之前有什么想法吗
谢谢。
-我在使用Spring3.2.6和Jersey 2.6时遇到了同样的问题。 我通过将Jersey升级到2.9.1版解决了这个问题 还要确保使用此依赖项使spring 3和jersey共存:
<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>
org.glassfish.jersey.ext
泽西-斯普林3
2.9.1
org.springframework
弹簧芯
有一个类似的问题可能会有所帮助:你最终真的发现了问题吗?不,我没有。我还没有机会回到这里。如果你不能使用任何高于2.6的版本,该怎么办?我必须使用JavaSE6,直到版本2.6,Jersey才使用JavaSE6编译。现在几乎所有Jersey组件都是使用JavaSE7目标编译的。因此,不幸的是,2.9.1版不适用于JavaSE7。