Win a copy of Getting started with Java programming language this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Listening to servlet.init() events.  RSS feed

 
preetika shukla
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Currently i am trying to build up a spring based application, where in the cases of any exceptions/errors being thrown while intialization of the context, the application itself should be brought down.
1. creating a appContext.xml where DBs are being initialized.
2. Cases where db isn't getting initialized since the context couldn't be initialized completely, we will get Servlet.init() error.
3. I want to intercept in between these two steps, where the application itself should be brought down,  in case of any errors

I have tried the following:
1. Using the error location handler in web.xml, creating a json stating that some error had occured. But this is not pre emptive, as in the application will keep on running.
2. Using events hook provided by spring, but there are only five of these: context start/stop/refresh/close/request handling. I have tried exploring custom events being raised, but I don't know where/how to publish/subscrive to these events.

can someone please help ?
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I haven't worked with Spring but for vanilla servlets, one would typically use a ServletContextListener
Your initialization code would go inside the contextInitialized() method.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!