java - JavaEE:尝试公开我的 Rest Web 服务时出现 Nullpointer
问题描述
您好,我正在尝试公开我的 Rest web 服务,但我不断收到 Null 指针异常。我不明白我的错,因为我从另一个项目中获得了代码并且它运行良好但是在我的项目中我得到了错误,如果你能识别错误请帮助我。
我以这种方式在 Employee Bean 中初始化了我的服务:
EmployeServiceASPemployeServiceASP=new EmployeServiceASP();
员工豆:
@GET
@Path("/all")
@Produces(MediaType.APPLICATION_JSON)
public Response getserviceHello() {
return `Response.status(Status.ACCEPTED).entity(employeServiceASP.getAll()).build();`
}
EmployeBean 导入:
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import tn.esprit.PiDev.persistence.Employe;
import tn.esprit.PiDev.services.EmployeServiceASP;
员工服务:
@Override
public List<Employe> getAll() {
Query q=em.createQuery("SELECT e FROM Employe e");
return q.getResultList();
}
休息激活器:
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
@ApplicationPath("/rest")
public class RestActivator extends Application {
}
这是错误:
00:05:23,165 错误 [io.undertow.request](默认任务 39)UT005023:对 /PiDev-web/rest/employe/all 的异常处理请求:org.jboss.resteasy.spi.UnhandledException:java.lang。 NullPointerException 在 org.jboss.resteasy.core.SynchronousDispatcher 的 org.jboss.resteasy.core.ExceptionHandler.handleException(ExceptionHandler.java:212) 的 org.jboss.resteasy.core.ExceptionHandler.handleApplicationException(ExceptionHandler.java:76)。 writeException(SynchronousDispatcher.java:149) at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:179) at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:372) .resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220) 在 org.jboss.resteasy.plugins.server。servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56) at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51) at javax.servlet.http.HttpServlet.service(HttpServlet.java: 790) 在 io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:86) 在 io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62) 在 io.undertow.servlet.handlers .ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) 在 org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78) 在 io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43 ) 在 io.undertow.servlet.handlers.security。SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131) 在 io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57) 在 io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)在 io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46) 在 io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64) 在 io.undertow.security.handlers.AuthenticationMechanismsHandler .handleRequest(AuthenticationMechanismsHandler.java:58) 在 io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:72) 在 io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76) 在 io.undertow.server.handlers.PredicateHandler 的 io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50) .handleRequest(PredicateHandler.java:43) 在 org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61) 在 io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) ) 在 io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:282) 在 io.undertow.servlet.handlers.ServletInitialHandler 的 io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)。 dispatchRequest(ServletInitialHandler.java:261) 在 io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:172) 在 io.undertow.server.Connectors 的 io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:80) .executeRootHandler(Connectors.java:199) at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:774) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent .ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) 原因:tn.esprit.PiDev.presentation.mbeans.EmployeBeanASP.getserviceHello 的 java.lang.NullPointerException (EmployeBeanASP.java:47) 在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 在 sun.reflect.NativeMethodAccessorImpl。invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.jboss.resteasy.core.MethodInjectorImpl .invoke(MethodInjectorImpl.java:137) 在 org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:296) 在 org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:250) 在 org. jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:237) 在 org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:356) ... 32 更多497) 在 org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:296) 在 org.jboss.resteasy.core.ResourceMethodInvoker .invoke(ResourceMethodInvoker.java:250) 在 org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:237) 在 org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:356) ...还有 32 个497) 在 org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:296) 在 org.jboss.resteasy.core.ResourceMethodInvoker .invoke(ResourceMethodInvoker.java:250) 在 org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:237) 在 org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:356) ...还有 32 个在 org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:356) 上调用(ResourceMethodInvoker.java:237) ... 还有 32 个在 org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:356) 上调用(ResourceMethodInvoker.java:237) ... 还有 32 个
解决方案
推荐阅读
- java - 流已被操作或关闭,尝试创建 Racers 时出现异常
- excel - 从 excel 运行 MS Word 邮件合并
- c# - 一个 Web 应用程序和工作两个地址 URL
- angular - Include a specific file in prod ng build
- html - 从浏览器请求 .html 页面时出现 IIS 10 错误(指定的 CGI 应用程序遇到错误)
- sql - 如何使用其他列查询聚合数据
- r - 根据值绘制一个仅行和仅点的变量
- php - Laravel Eloquent 按字母数字值排序
- javascript - onClick 事件无法在 FullCalendar 中使用带有 dayRender 的 innerHTML
- windows - 我应该安装什么驱动程序来恢复“SCardTransmit got response 0x57”错误?