-1

I'm working on developing new Spring web applications, on a team that's developed a ton of web apps around Vanilla HttpServlet's. I'm new to Spring (please don't run!) and I'm doing my best to find a tutorial, reference document, book, anything to help me leverage a "Vanilla Servlet".

I was able to work around my last issue, by invoking the a particular Servlet I needed from the (Flex) client's browser. The trouble now is, I have another Servlet (the source of which, I can't modify) that I need to call when my application is started. The Servlet is involved in initializing application reference data (so this is really critical).

It seems to me this should be a typical problem... This must have been a common issue a few years ago when other teams converted to Spring, so why can't I find the tutorial I need? I've tried researching a ton of different Spring classes, but I'm not getting anywhere on this.

Here's some notes on what I've tried:

  • ServletWrappingController , but this isn't for use as a Controller, I really only need the Servlet inside a Singleton DAO's Constructor.
  • ResourceServlet , this Class name seems appropriate, and I've run across it in my searching, but I'm not entirely sure if this is something that would help.
  • ServletForwardingController (mentioned here), but I can't seem to find an appropriate example.
  • ServletWrappingController (also from the above question), but -again- I can't find an appropriate example.

Am I on a wild goose hunt here? Is there a way that I can invoke a static method (does that matter?) on a Servlet, during a Spring app's startup?

I'm not sure a code snippet will help, but I'd be happy to post one. Really, my only tangential thoughts are "Does the Servlet need to be declared a particular way in web.xml" and "Does this need to be declared a certain way in as a Spring managed bean?" (i.e. in app-config.xml)

I can't edit the Servlet, though I can tell you it does extend HttpServlet. I'm not calling doGet or doPost on it, instead there's a static method on the Servlet that makes an RPC call that I need to invoke. If anyone knows a special @MagicInjectHttpServlet annotation, please pass it on!

Community
  • 1
  • 1
blong
  • 2,815
  • 8
  • 44
  • 110
  • I don't do Spring, but in normal Servlet API you'd use a `ServletContextListener` for this. A Servlet is intented to act on individual HTTP requests, not to do some global initialization. – BalusC Apr 07 '11 at 01:34
  • Well, I'm not sure if the question is Spring specific in that way or not... If it were possible, I'd think maybe the Servlet container or Spring would let you "mock" one HTTP request / session to perform _some_ initialization. Have you come across anything of that sort? – blong Apr 07 '11 at 01:40
  • Can you explain what you mean by "leverage"? What are you hoping to use from the existing servlet - invoke member methods in it, it's doGet(), etc ? – matt b Apr 07 '11 at 02:22

1 Answers1

0

I'm not sure I completely understand what you need, but if it's geniunely just a static method that you need to call, I would have thought that:

<bean id="myLegacyServlet" 
       class="com.legacy.thing.Servlet"
       init-method="thatStaticMethod" />

and

<bean id="myGoodStuff" 
       class="com.my.stuff.MyStuff" 
       depends-on="myLegacyServlet">
    ...
</bean>

would be sufficient. The fact that your legacy object is a servlet shouldn't make any difference - the important thing is making sure that init-method gets called nice and early, and the best way I can think of is declaring that some other bean needs your legacy bean.

millhouse
  • 9,817
  • 4
  • 32
  • 40
  • sorry for my delayed response. This seems to be the correct answer. It took me ages to get to the root cause of the errors I was having and it all came back to the Classpath. Of course, that was way down the line of Spring issue? --> WEB-INF/lib? --> Servlet? --> Native libraries (dll's) the Servlet invokes? --> Server configuration? --> Classpath inside/outside eclipse discrepancies. The reason I believe this is the correct answer, is because I had these same two beans you've listed in my config, before all of my errors started! I'll re-write & expand on this after lunch! :) – blong Apr 21 '11 at 16:58