Show setting after "Initialization of context failed"

I am looking for a couple of days to answer the following question:

I have a Spring 2.5 web application, and I want to show a specific configuration screen if the initialization of the spring context failed. On this settings screen, they can see why the server does not start and can make some changes (download the new config.properties file)

But how can I implement this in a smart way? Does spring have something similar or do I need to extend ContextLoader for example?

I tried something in the web.xml file like this: but this does not work:

  <error-page> <error-code>404</error-code> <location>/public/setup.jsp</location> </error-page> 

Decision:

I start with the default web.xml file and after the installation is complete, I replace web.xml with the correct web.xml โ€œapplicationโ€. Due to the replacement of web.xml, the server is rebooting. This works great. Thanks again for your answers.

+4
source share
1 answer

Here are three ideas:

  • Modify the context loader to catch the exception, and add the servlet / map to a container that redirects all matching maps to the dynamically loaded servlet. Check out this stream of instructions on how to create a dynamic servlet: Dynamically add a servlet to servletConfig
  • Alternatively, you can install a standard servlet that processes all requests and sends them to the configuration page. Then you can have a spring bean that removes the servlet and collation from the context when it finishes initializing (you might want to put this code in the postInitalize spring bean hook.)
  • You can also try creating a listener that checks if a valid application context exists and removes the "default" outputs / servlet output.

I do not think that there are standard mechanisms for adding / removing servlets and displaying from the container. But it looks like most containers have some APIs that do this.

There is a third method that you hinted at. It is assumed that if 404 error occurred, the servlet did not start. If you go down this route, I think you will encounter a problem that 404 errors can occur only because the user fat has touched the URL.

+3
source

All Articles