The correct way to handle java web application startup error

I am currently writing a java web application that performs certain checks at startup. Example: checking the presence of a configuration file and determining all the necessary variables.

I placed the control code inside a subclass of the class ServletContextListenerand registered the subclass of ServletContextListener inside web.xml using:

<listener>
    <listener-class>com.bloxware.lls3.MainContextListener</listener-class>
</listener>

In the overridden contextInitialized () method, I wrote code that validates the configuration file in place and contains valid values.

If an error occurred during startup, I want to register this error and inform the web user accordingly.

I need help on how to move on from here :

  • Am I reading the configuration file settings in the right place (inside the ServletContextListener.contextInitialized (..) method)?

  • How can I handle showing the error page to the user after that (for example, should I add code to each servlet and jsp page to check the global flag, or can I do it more intelligently, maybe ServletRequestListener.requestInitialized (..))?

  • I need a way that if the user corrects the configuration file, it is enough to refresh the page and there is no need to restart the web application.

+3
source share
1 answer

I can respect the goal of having a dynamic configuration that tests itself, but really I would not suggest going this route.

( ) - , . , . , , . , . . - , , . , , - .

. , , , ( !) .

, . , -, . , , . () .

, , . , .

EDIT: . , , - , , , , . unit test .

+2

Source: https://habr.com/ru/post/1787113/


All Articles