0

Is there a good way to print information when Spring is done initializing everything and Tomcat is up and ready for service? I'd like to display a small banner (like Spring boot does, though I'm not using Spring boot), and print out some stuff like environmental variables and the status of the database connection, etc. Stuff that would make a nice health check after the server comes up.

I can definitely print this stuff out in the middle of the log, but I'd really like these messages to show up when the server is up and running.

Jazzepi
  • 5,259
  • 11
  • 55
  • 81

1 Answers1

0

Luiggi Mendoza pointed me in the right direction. Here's my solution.

@WebListener
public class Banner implements ServletContextListener {

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        System.out.println(System.getenv());
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {

    }
}

You need servlets 3.0 or greater to use @Weblistener.

Jazzepi
  • 5,259
  • 11
  • 55
  • 81