EJB注入Restful服务(NullPointerException) [英] EJB injection into Restful service (NullPointerException)
本文介绍了EJB注入Restful服务(NullPointerException)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在将StoreBean注入Restful服务时遇到问题。我有一点点reduecd代码来获得一点。
I' have a problem with injecting StoreBean into Restful service. I have reduecd code little bit to get a point.
这是代码(DataStoreBean):
Here is the code(DataStoreBean):
@Local(DataStore.class)
@Stateless
public class DataStoreBean implements DataStore
{
public String get()
{
return "works";
}
}
这里是RestEndpoint的代码:
and here is code for RestEndpoint:
@RequestScoped
@Path("/DataStore")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class DataStoreRestEndpoint
{
@EJB
DataStoreBean dataStore;
@GET
@Path("/test")
public String get()
{
return dataStore.get();
}
}
当我执行时,我总是得到一个NPE。
When I executed I always get a NPE.
Caused by: java.lang.NullPointerException
at org.it.datastore.DataStoreRestEndpoint.get(DataStoreRestEndpoint.java:112) [classes:]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_25]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) [rt.jar:1.7.0_25]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) [rt.jar:1.7.0_25]
at java.lang.reflect.Method.invoke(Unknown Source) [rt.jar:1.7.0_25]
at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:155) [resteasy-jaxrs-2.3.1.GA.jar:]
at org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:257) [resteasy-jaxrs-2.3.1.GA.jar:]
at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:222) [resteasy-jaxrs-2.3.1.GA.jar:]
at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:211) [resteasy-jaxrs-2.3.1.GA.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:525) [resteasy-jaxrs-2.3.1.GA.jar:]
... 19 more
我正在使用JBoss 7.1和EJB3
I'm using JBoss 7.1 and EJB3
推荐答案
使用@Stateless声明restful类。下面是一个示例:将EJB注入JAX-RS(RESTful服务)
Declare the restful class with @Stateless, too. Here is an example: Inject an EJB into JAX-RS (RESTful service)
这篇关于EJB注入Restful服务(NullPointerException)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文