问题
I got a requirement to write a log line when all wars have been deployed. Is there an observer pattern for Tomcat's deployer I could hook onto?
On first start jBoss/Tomcat send out a line with exact time spent on startup. Not perfect... but works.
But on hot deploy no notification/log is sent/written :(
(There are around 100 servlets in the project and it's a risk to list them all in order and then guess that the deployment is finished once the last one initializes, so let's try to skip solutions of that kind)
Any hints?
回答1:
Did you look at JBoss JMX API? Among others there is a MainDeployer MBean that lets you manage deployments, it has a method listIncompletelyDeployed()
which you can call to check what's not yet deployed. A ListenerServiceMBeanSupport allows you to subscribe for JMX notifications.
Well I cannot give you an exact solution, but poking around the JMX may bring you what you need.
回答2:
I think that javax.servlet.ServletContextListener
could be what you want:
http://download.oracle.com/javaee/5/api/javax/servlet/ServletContextListener.html
I see lifecycle events for context created and destroyed. Perhaps that, combined with servlet init and destroy methods for individual servlets, can help.
来源:https://stackoverflow.com/questions/6610370/jboss-tomcat-deploy-listener