0
我無法注入Resteasy中的cdi bean。在調試時,它似乎總是顯示空指針異常。即下面代碼中的'jaxRsImpl'始終爲空。我想在JBoss EAP運行6.2無法注入CDI Bean休息Easy
@Path("/jaxrs-service")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class JAXRSService {
@Inject
private JAXRSImpl jaxRsImpl;
@POST
@Path("/authenticate")
@Consumes(MediaType.APPLICATION_JSON)
public Response authenticate(Credentials user) {
return jaxRsImpl.authenticate(user);
}
}
而我打算注入類是
@RequestScoped
public class JAXRSImpl {
public Response authenticate(Credentials user) {
// Some logic
}
}
我的應用程序是網絡,所以我增加了在beans.xml裏面WEB-INF文件夾
我的初始化器看起來像
@ApplicationPath("/rest")
public class JAXRSInitializer extends Application {
private Set<Object> singletons = new HashSet<Object>();
private Set<Class<?>> classes = new HashSet<Class<?>>();
public JAXRSInitializer() {
singletons.add(new JAXRSService());
classes.add(JAXRSImpl.class);
}
@Override
public Set<Class<?>> getClasses() {
return classes;
}
@Override
public Set<Object> getSingletons() {
return singletons;
}
}
我刪除了JAXRSInitializer中的所有內容,並且它工作正常 – Licht 2014-12-07 19:13:34