• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Is it possible to catch Servlet.init() exceptions in spring

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi team,
I am a bit new to Spring framework. In my application,we are using servlet-context.xml to create the beans required for  DB. For some reason say at some time if the DB was down, or some other bean creation erred out, I am getting a Servlet.init() error and the complete stack trace is being shown at the jsp context.
Is it possible to catch these exceptions and throw a minimalist error saying, something went wrong, so that the end user isn't being shown all the stack trace.
I have tried using the controllerAdvice annotation as suggested by everyone, But if the sping application was itself unable to bootstrap, how will these annotations help me out?      
stuck on this since two dats  
Any insights will be deeply appreciated.
Regards,
jeangrey
 
Sheriff
Posts: 9697
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Preetika, welcome to CodeRanch.

I think in such a case, you'll have to define the error page in web.xml as I believe the stack trace is shown by the default error page of Tomcat (or whatever server you are using). See examples here on how to setup your own error page in web.xml...
 
preetika shukla
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ankit Garg wrote:Hi Preetika, welcome to CodeRanch.

I think in such a case, you'll have to define the error page in web.xml as I believe the stack trace is shown by the default error page of Tomcat (or whatever server you are using). See examples here on how to setup your own error page in web.xml...



Thanks Ankit   , But i see the references you've provided are for standard J2ee , where servlets are serving the requests using doget/doPost methods. is it possible to redo the same using spring controllers ?

 
Ankit Garg
Sheriff
Posts: 9697
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Spring also works by adding a Servlet to your web.xml (DispatcherServlet) so I would assume it would work as your DispatcherServlet is probably using the default error page of the server when the Spring startup fails. Did you try it and it didn't work? Since you are talking about a scenario where the context start fails, I don't know how you'll be able to do it with a Spring controller...
 
preetika shukla
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ankit Garg wrote:Spring also works by adding a Servlet to your web.xml (DispatcherServlet) so I would assume it would work as your DispatcherServlet is probably using the default error page of the server when the Spring startup fails. Did you try it and it didn't work? Since you are talking about a scenario where the context start fails, I don't know how you'll be able to do it with a Spring controller...



Ankit, thanks for the help, I've used the error-page in web.xml    
 
Ranch Hand
Posts: 531
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

preetika shukla wrote:hi team,
I am a bit new to Spring framework. In my application,we are using servlet-context.xml to create the beans required for  DB. For some reason say at some time if the DB was down, or some other bean creation erred out, I am getting a Servlet.init() error and the complete stack trace is being shown at the jsp context.
Is it possible to catch these exceptions and throw a minimalist error saying, something went wrong, so that the end user isn't being shown all the stack trace.
I have tried using the controllerAdvice annotation as suggested by everyone, But if the sping application was itself unable to bootstrap, how will these annotations help me out?      
stuck on this since two dats  
Any insights will be deeply appreciated.
Regards,
jeangrey



Hi, Preetika, my two cents is to avoid exposing Servlets as a technology behind your Spring-based application as much as possible except for addons that depend on it directly, such as Spring Security.

With best regards,

Anton.

 
preetika shukla
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Hi, Preetika, my two cents is to avoid exposing Servlets as a technology behind your Spring-based application as much as possible except for addons that depend on it directly, such as Spring Security.

With best regards,

Anton.



Anton,
Thanks for the insights but are you aware of any other way of doing this ?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic