What is the purpose of Meta-INF services in Java ?
The META-INF directory, if it exists, is used to store package and extension configuration data, including security, versioning, extension and services.
It searches for service providers on your application's class path or in your runtime environment's extensions directory. It loads them and enables your application to use the provider's APIs. If you add new providers to the class path or runtime extension directory, the ServiceLoader class finds them.
Service provider interface (SPI) is an API intended to be implemented or extended by a third party. It can be used to enable framework extension and replaceable components.
It's intended to store service provider configuration files.
A Service provider is an implementation of a Service Provider Interface packaged as JAR.
A Service loader discover and load all implementations declared in the service provider configuration file.
A configuration file is a file named as the fully qualified name of the interface and its content is a list of fully qualified names of implementations.
Following is an example of provider configuration file for javax.servlet.ServletContainerInitializer that is used by Servlet 3.0 at webapp startup.
org.apache.jasper.servlet.JasperInitializer org.springframework.web.SpringServletContainerInitializer
In this example
When tomcat startup webapp call both
onStartup(java.util.Set<java.lang.Class<?>> types, ServletContext context)
methods on JasperInitializer and SpringServletContainerInitializer classes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With