Integrating both spring mvc and Jersey, getting a null pointer when viewing a jersey endpoint?

Make sure your myapp-servlet. Xml contains the following.

Up vote 0 down vote favorite share g+ share fb share tw.

My simple jersey endpoint: @Component @Path("/v1/user") public class UserService { @Autowired com.myapp.core.service. UserService userService; @GET @Path("/get") public Response getUser() { User user = userService. GetUser(1); String result = user.getUsername(); return Response.

Status(200). Entity(result).build(); } } (BTW, since this is restful, will this be an xml or json output? ) My spring mvc pages working fine (that hit hibernate), but when I visit localhost:8080/api/v1/user/get I see: java.lang.

NullPointerException com.myapp.api.UserService. GetUser(UserService. Java:30) sun.reflect.

NativeMethodAccessorImpl. Invoke0(Native Method) sun.reflect. NativeMethodAccessorImpl.

Invoke(NativeMethodAccessorImpl. Java:39) sun.reflect. DelegatingMethodAccessorImpl.

Invoke(DelegatingMethodAccessorImpl. Java:25) java.lang.reflect.Method. Invoke(Method.

Java:597) com.sun.jersey.spi.container. JavaMethodInvokerFactory$1. Invoke(JavaMethodInvokerFactory.

Java:60) com.sun.jersey.server.impl.model.method.dispatch. AbstractResourceMethodDispatchProvider$ResponseOutInvoker. _dispatch(AbstractResourceMethodDispatchProvider.

Java:205) com.sun.jersey.server.impl.model.method.dispatch. ResourceJavaMethodDispatcher. Dispatch(ResourceJavaMethodDispatcher.

Java:75) com.sun.jersey.server.impl.uri.rules.HttpMethodRule. Accept(HttpMethodRule. Java:288) com.sun.jersey.server.impl.uri.rules.

RightHandPathRule. Accept(RightHandPathRule. Java:147) com.sun.jersey.server.impl.uri.rules.

ResourceClassRule. Accept(ResourceClassRule. Java:108) com.sun.jersey.server.impl.uri.rules.

RightHandPathRule. Accept(RightHandPathRule. Java:147) com.sun.jersey.server.impl.uri.rules.

RootResourceClassesRule. Accept(RootResourceClassesRule. Java:84) com.sun.jersey.server.impl.application.

WebApplicationImpl. _handleRequest(WebApplicationImpl. Java:1469) com.sun.jersey.server.impl.application.

WebApplicationImpl. _handleRequest(WebApplicationImpl. Java:1400) com.sun.jersey.server.impl.application.

WebApplicationImpl. HandleRequest(WebApplicationImpl. Java:1349) com.sun.jersey.server.impl.application.

WebApplicationImpl. HandleRequest(WebApplicationImpl. Java:1339) com.sun.jersey.spi.container.servlet.WebComponent.

Service(WebComponent. Java:416) com.sun.jersey.spi.container.servlet. ServletContainer.

Service(ServletContainer. Java:537) com.sun.jersey.spi.container.servlet. ServletContainer.

Service(ServletContainer. Java:699) javax.servlet.http.HttpServlet. Service(HttpServlet.

Java:717) My web. Xml: myapp myapp contextConfigLocation /WEB-INF/spring/applicationContext. Xml /WEB-INF/spring/myapp-servlet.

Xml myapp org.springframework.web.servlet. DispatcherServlet contextConfigLocation /WEB-INF/spring/myapp-servlet. Xml 1 myapp / org.springframework.web.context.

ContextLoaderListener jersey-servlet com.sun.jersey.spi.spring.container.servlet. SpringServlet com.sun.jersey.config.property. Packages com.myapp.

Api 2 jersey-servlet /api/* My application context has beans for: dataSource, sessionFactory and userDao. My myapp-servlet. Xml has: (both applicationContext and myapp-servlet.

Xml have the same xml header node etc. in case that is an issue? ) java hibernate spring-mvc jersey link|improve this question edited Nov 21 '11 at 5:23skaffman114k8136227 asked Nov 21 '11 at 4:38Blankman13.3k24100257 60% accept rate.

Make sure your myapp-servlet. Xml contains the following: About media-type of request/response - you can specify it explicitly, like this: @Produces({MediaType. APPLICATION_JSON}) @Consumes({MediaType.

APPLICATION_JSON}) @Path("/v1/user") public class UserService {... Default value is "*/*" - any type. Useful info about jersey annotation can be found here.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions