Servlet.staticMethod used to initialize Spring reference data?
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!
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.
精彩评论