Interface ServletContainerInitializer
-
public interface ServletContainerInitializerInterface which allows a library/runtime to be notified of a web application's startup phase and perform any required programmatic registration of servlets, filters, and listeners in response to it.Implementations of this interface may be annotated with
HandlesTypes, in order to receive (at theironStartup(java.util.Set<java.lang.Class<?>>, javax.servlet.ServletContext)method) the Set of application classes that implement, extend, or have been annotated with the class types specified by the annotation.If an implementation of this interface does not use
HandlesTypesannotation, or none of the application classes match the ones specified by the annotation, the container must pass anullSet of classes toonStartup(java.util.Set<java.lang.Class<?>>, javax.servlet.ServletContext).When examining the classes of an application to see if they match any of the criteria specified by the
HandlesTypesannotation of aServletContainerInitializer, the container may run into classloading problems if any of the application's optional JAR files are missing. Because the container is not in a position to decide whether these types of classloading failures will prevent the application from working correctly, it must ignore them, while at the same time providing a configuration option that would log them.Implementations of this interface must be declared by a JAR file resource located inside the
META-INF/servicesdirectory and named for the fully qualified class name of this interface, and will be discovered using the runtime's service provider lookup mechanism or a container specific mechanism that is semantically equivalent to it. In either case,ServletContainerInitializerservices from web fragment JAR files excluded from an absolute ordering must be ignored, and the order in which these services are discovered must follow the application's classloading delegation model.- Since:
- Servlet 3.0
- See Also:
HandlesTypes
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidonStartup(java.util.Set<java.lang.Class<?>> c, ServletContext ctx)Notifies thisServletContainerInitializerof the startup of the application represented by the givenServletContext.
-
-
-
Method Detail
-
onStartup
void onStartup(java.util.Set<java.lang.Class<?>> c, ServletContext ctx) throws ServletExceptionNotifies thisServletContainerInitializerof the startup of the application represented by the givenServletContext.If this
ServletContainerInitializeris bundled in a JAR file inside theWEB-INF/libdirectory of an application, itsonStartupmethod will be invoked only once during the startup of the bundling application. If thisServletContainerInitializeris bundled inside a JAR file outside of anyWEB-INF/libdirectory, but still discoverable as described above, itsonStartupmethod will be invoked every time an application is started.- Parameters:
c- the Set of application classes that extend, implement, or have been annotated with the class types specified by theHandlesTypesannotation, ornullif there are no matches, or thisServletContainerInitializerhas not been annotated withHandlesTypesctx- theServletContextof the web application that is being started and in which the classes contained incwere found- Throws:
ServletException- if an error has occurred
-
-