Both ServletContextEventHandler and static block have high startup priority. In usage, what is the difference? What should be put in the SC event handler and the static block?
Thanks Ming
Both ServletContextEventHandler and static block have high startup priority. In usage, what is the difference? What should be put in the SC event handler and the static block?
Thanks Ming
I think you have a misunderstanding of the lifecycle of classes and objects.
A static
block is executed when a class is loaded and this more or less depends on the ClassLoader
your application is using. In a static
context you only have access to other static
components.
An object of type ServletContextEventHandler
, by which I assume you mean ServletContextListener
, is a hook that you can use to access your application's ServletContext
when it is initialized and when it is destroyed.