Win a copy of React Cookbook: Recipes for Mastering the React Framework this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

Google SystemServiceServlet and Spring IOC

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Guys,
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.


web.xml



endpoint-business.xml



Java Endpoint Service Defined in the Google SystemServiceServlet. My Autowired userService is null when I call the createUser endpoint.


UserService.java


 
anakin volpy
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
anakin volpy
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Do not set lab on fire. Or this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic