JavaEE:尝试公开我的Rest Web Service时为Nullpointer

时间:2018-11-25 23:10:56

标签: java rest web-services jax-ws

您好,我正在尝试公开我的Rest Web Service,但我一直收到Null指针异常。我不理解我的错,因为我从另一个项目中获得了代码,并且运行良好,但是在我的项目中,我得到了一个错误,如果您能确定错误,请帮助我。

我以这种方式在Employee Bean中初始化了我的服务:

EmployeServiceASP受雇人员Servicee =新的EmployeServiceASP();

EmployeeBean:

@GET
@Path("/all")
@Produces(MediaType.APPLICATION_JSON) 
public Response getserviceHello() {
    return `Response.status(Status.ACCEPTED).entity(employeServiceASP.getAll()).build();`
}

EmployeBeanImport:

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();
}

RestActivator:

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.ExceptionHandler.handleApplicationException(ExceptionHandler.java:76)     在   org.jboss.resteasy.core.ExceptionHandler.handleException(ExceptionHandler.java:212)     在   org.jboss.resteasy.core.SynchronousDispatcher.writeException(SynchronousDispatcher.java:149)     在   org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:372)     在   org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:179)     在   org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220)     在   org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)     在   org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)     在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.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)     在   io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76)     在   io.undertow.server.handlers.PredicateHandler.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.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)     在   io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:282)     在   io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:261)     在   io.undertow.servlet.handlers.ServletInitialHandler.access $ 000(ServletInitialHandler.java:80)     在   io.undertow.servlet.handlers.ServletInitialHandler $ 1.handleRequest(ServletInitialHandler.java:172)     在   io.undertow.server.Connectors.executeRootHandler(Connectors.java:199)     在   io.undertow.server.HttpServerExchange $ 1.run(HttpServerExchange.java:774)     在   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)     在   java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:617)     在java.lang.Thread.run(Thread.java:745)造成原因:   java.lang.NullPointerException在   tn.esprit.PiDev.presentation.mbeans.EmployeBeanASP.getserviceHello(EmployeBeanASP.java:47)     在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     在   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     在java.lang.reflect.Method.invoke(Method.java:497)在   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个

PostMan结果: enter image description here

0 个答案:

没有答案