Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6661413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:16:36+00:00 2026-05-26T02:16:36+00:00

I have a webapp running in Tomcat which uses Spring for dependency injection. (It’s

  • 0

I have a webapp running in Tomcat which uses Spring for dependency injection. (It’s a GWT application, but I don’t think that makes much of a difference to the solution I’m looking for.)

My web.xml file is of the following format:

<web-app>
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!-- Servlets -->
<servlet>
    <servlet-name>dispatch</servlet-name>
    <servlet-class>com.example.my.gwt.dispatch.DispatchServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>dispatch</servlet-name>
    <url-pattern>/my_gwt/dispatch</url-pattern>
</servlet-mapping>

    ... more servlets ...

</web-app>

One of the things my Spring configuration does is to connect to a databse via Hibernate:

<bean id="datasource"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="${db.driver}" />
    <property name="url"
        value="${db.url}" />
    <property name="username" value="${db.username}" />
    <property name="password" value="${db.password}" />
</bean>
<bean id="databaseSessionFactory"
    class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="dataSource" ref="datasource" />
    <property name="packagesToScan">
        <array>
            <value>com.example.my.gwt.model</value>
        </array>
    </property>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.hbm2ddl.auto">update</prop>
        </props>
    </property>
</bean>

If the database is unavailable, this causes an org.h2.jdbc.JdbcSQLException to be thrown, so the Spring initialisation does not continue, so the rest of the webapp cannot be used. Navigating to the webapp’s URL gives an HTTP 503 ‘Service Unavailable’ error.

What I want to do is to catch that error and display a page to the user (when they first navigate to the app) explaining what the problem is likely to be and suggested fixes. How can I do this?

I have tried using a custom ContextLoaderListener class that delegates to the one in the XML above, but catches any exceptions. This allows me to catch the exception, but there is not much I can do – the web.xml is still pointing the user’s request to a servlet that is not running after the Spring initialisation has failed. Is there any way that I can change the webapp config when I catch that exception, so that it doesn’t try to load the servlets from the web.xml and perhaps changes the welcome file to point to a page about the error? Or is there any other way that I can make the webapp gracefully handle this exception?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:16:36+00:00Added an answer on May 26, 2026 at 2:16 am

    Basically you’re asking if you can have a functioning web application after the web application fails to start up.

    You could try configuring a 503 handler page and/or have a welcome page, not dependent on Spring, that checks for something in the application context that’s set only on a good spin up. If it didn’t spin up, the exception you’ve already captured could be placed into the app context.

    Not sure if anything in the app, even web.xml-only resources, if Spring doesn’t spin up, though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a GWT webapp, running under Tomcat, with the following remote service: public
I have a Tomcat 5.5 running which includes a Webapp with the Java Reporting
multiple webapp running on same tomcat using same jvm. sometime, one webapp that have
We have a (non-web app) Spring application that throws a NoSuchBeanDefinitionException when running tests
I have a Java webapp running on Tomcat. At runtime, I create images files
I have a servlet based webapp running on Tomcat 6 server. The URL scheme
I have a tomcat server running a webapp. Apart from this there are two
We have a web application running on Tomcat 7 and it loads a JNI
We have a simple Webapp running on two Tomcat instances behind Apache (a Tomcat
I have a java web application running under tomcat in a Sun java 6

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.