我正在使用struts2,hibernate,spring和jersey使用REST创建应用程序。我的应用程序的所有部分都在工作,但是在我的REST中,我得到了空指针
javax.servlet.ServletException: java.lang.NullPointerException org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:487) org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:425) org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:383) org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:336) org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:223) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393) cause mère java.lang.NullPointerException com.project.caritas.rest.MedicamentJsonRest.getMedicament(MedicamentJsonRest.java:35) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:483) org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81) org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:144) org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:161) org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$TypeOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:205) org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:99) org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:389) org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:347) org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102) org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:326) org.glassfish.jersey.internal.Errors$1.call(Errors.java:271) org.glassfish.jersey.internal.Errors$1.call(Errors.java:267) org.glassfish.jersey.internal.Errors.process(Errors.java:315) org.glassfish.jersey.internal.Errors.process(Errors.java:297) org.glassfish.jersey.internal.Errors.process(Errors.java:267) org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317) org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:305) org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1154) org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:471) org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:425) org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:383) org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:336) org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:223) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
我的春季配置看起来像这样
还有我的REST课程
@Path("/json/medicaments") public class MedicamentJsonRest { private MedicamentService medicamentService; @GET @Path("/find") @Produces({MediaType.APPLICATION_JSON}) public Medicaments getMedicament(){ Medicaments m = new Medicaments(); try { m = medicamentService.find(1); } catch (NonExistentEntityException ex) { Logger.getLogger(MedicamentJsonRest.class.getName()).log(Level.SEVERE, null, ex); } return m; } /** * @return the medicamentService */ public MedicamentService getMedicamentService() { return medicamentService; } /** * @param medicamentService the medicamentService to set */ public void setMedicamentService(MedicamentService medicamentService) { this.medicamentService = medicamentService; } }
Web.xml球衣配置
Jersey Web Application org.glassfish.jersey.servlet.ServletContainer javax.ws.rs.Application com.project.caritas.rest.RestApplication 1 Jersey Web Application /rest/*
我的问题是为什么medicamentService具有null值,Spring无法处理?谢谢您的回答,对不起我的英语不好