我想MyService
使用 CDI 直接注入我的 JerseyTest。是否可以?MyService
已成功注入MyResource
,但当我尝试从 MyJerseyTest 访问它时出现 NullPointerException。
public class MyResourceTest extends JerseyTest {
@Inject
MyService myService;
private Weld weld;
@Override
protected Application configure() {
Properties props = System.getProperties();
props.setProperty("org.jboss.weld.se.archive.isolation", "false");
weld = new Weld();
weld.initialize();
return new ResourceConfig(MyResource.class);
}
@Override
public void tearDown() throws Exception {
weld.shutdown();
super.tearDown();
}
@Test
public void testGetPersonsCount() {
myService.doSomething(); // NullPointerException here
// ...
}
}