WebappServiceLoader (Apache Tomcat 11.0.6 API Documentation)
Description: declaration: package: org.apache.catalina.startup, class: WebappServiceLoader

# Class WebappServiceLoader<T>

java.lang.Object
org.apache.catalina.startup.WebappServiceLoader<T>

Type Parameters:
  `T` - The type of service to load

public class WebappServiceLoader<T> extends Object
A variation of Java's JAR ServiceLoader that respects exclusion rules for web applications.

Primarily intended for use loading ServletContainerInitializers as defined by Servlet 8.2.4. This implementation does not attempt lazy loading as the container is required to introspect all implementations discovered.

If the ServletContext defines ORDERED_LIBS, then only JARs in WEB-INF/lib that are named in that set will be included in the search for provider configuration files; if ORDERED_LIBS is not defined then all JARs will be searched for provider configuration files. Providers defined by resources in the parent ClassLoader will always be returned.

Provider classes will be loaded using the context's ClassLoader.

See Also:
  - `ServletContainerInitializer`
  - `ServiceLoader`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `WebappServiceLoader(Context context)`
  Construct a loader to load services from a ServletContext.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `List<T>`
  `load(Class<T> serviceType)`
  Load the providers for a service type.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### WebappServiceLoader

    public WebappServiceLoader(Context context)
    Construct a loader to load services from a ServletContext.
    Parameters:
      `context` - the context to use

- ## Method Details

  - ### load

    public List<T> load(Class<T> serviceType) throws IOException
    Load the providers for a service type. Container defined services will be loaded before application defined services in case the application depends on a Container provided service. Note that services are always loaded via the Context (web application) class loader so it is possible for an application to provide an alternative implementation of what would normally be a Container provided service.
    Parameters:
      `serviceType` - the type of service to load
    Returns:
      an unmodifiable collection of service providers
    Throws:
      `IOException` - if there was a problem loading any service