I need to run some code when the FacesServlet starts, but as FacesServlet is declared final I can not extend it and overwrite the init() method.
In particular, I want to write some data to the database during development and testing, after hibernate has dropped and created the datamodel.
Is there a way to configure Faces to run some method, e.g. in faces-config.xml?
Or is it best to create a singleton bean that does the initialization?
Use an eagerly initialized application scoped managed bean.
(class and method names actually doesn’t matter, it’s free to your choice, it’s all about the annotations)
This is guaranteed to be constructed after the startup of the
FacesServlet, so theFacesContextwill be available whenever necessary. This in contrary to theServletContextListeneras suggested by the other answer.