Skip to content

META-INF/services service provider mechanism

The META-INF/services service provider mechanism is a standard Java convention used to register implementations (service providers) so that they can be discovered and instantiated automatically by a runtime or framework^[600-developer__java__spring__ServletContainerInitializer.md#L11-L13].

Overview

This mechanism allows for decoupled architecture where the core logic defines an interface or abstract class, and specific implementations are provided in separate JAR files. At runtime, the system scans for specific text files located in the META-INF/services directory to determine which classes to load^[600-developer__java__spring__ServletContainerInitializer.md#L11-L13].

File Format and Registration

To register a service provider, a file must be created within the JAR archive at the path META-INF/services/[FullyQualifiedInterfaceName].^[600-developer__java__spring__ServletContainerInitializer.md#L11-L13]

  • Directory: META-INF/services
  • Filename: The fully qualified binary name of the service's abstract class or interface (e.g., javax.servlet.ServletContainerInitializer).
  • Content: The file contains a list of fully qualified class names of the concrete implementations, with one class name per line^[600-developer__java__spring__ServletContainerInitializer.md#L12-L13].
  • Example: To register a Spring initializer, the file META-INF/services/javax.servlet.ServletContainerInitializer would contain the entry org.springframework.web.WebApplicationInitializer^[600-developer__java__spring__ServletContainerInitializer.md#L12-L13].

Sources

^[600-developer__java__spring__ServletContainerInitializer.md]