I'm trying to utilize spring and google endpoints but having a pretty fundamental problem. I'm getting a NPE when accessing an autowired service bean from my SystemServiceServlet endpoint(Java code below). Shouldn't the endpoint-business.xml beans be defined in the root context to be shared amongst the servlets? Which means the SystemsServiceServlet should have access to these beans correct? Any idea how I can get these wired up correctly. I must admit, usually when coding putting web contexts we have a pretty standard formula we follow and its a simple copy paste which is why I'm a bit fuzzy in this area. Below is the code. Thanks for any help guys.
Java Endpoint Service Defined in the Google SystemServiceServlet. My Autowired userService is null when I call the createUser endpoint.
I noticed that service class in SystemServiceServlet is not initialized until the first request is made to the servlet. So it makes sense that the autowiring isn't working because the class simply isn't initialized yet. Anybody have any recommendations to get around this?
Hey Guys, I got this figured out so figured I'd post a solution here. Anyway, the container loads servlets as it feels necessary. I'm usually used to servlets initializing on deployment, but this isn't always the case. Therefore some containers will not load a servlet until the first request is mapped to it. This is why sometimes after a deployment, your initial request to a service takes a bit of time. To fix this, simply use the below code in your servlet definition in the web.xml
So your servlet definition would look something like this.