Home  >  Article  >  Java  >  What is Java's SPI?

What is Java's SPI?

WBOY
WBOYforward
2023-05-06 18:28:231580browse

Concept

1. SPI is a service provider interface. The JDK’s built-in service provider discovery mechanism is a third-party implementation or extended API provided by Java, which can be used to enable framework extensions and Replace components.

Specific conventions of Java SPI

When it is under the classpath, a file named after the service interface is also created in the META-INF/services/ directory under the classpath. This file is the specific implementation category that implements this service interface.

When an external program assembles the module, you can find the specific implementation category name through the configuration file in the jar package META-INF/services/, and load the instance to complete the module injection.

2. The caller enables, extends or replaces the framework's implementation strategy according to actual needs.

Common examples:

The database driver loading interface implements class loading.

JDBC load drives different types of databases.

Logging logging interface implementation class loading.

SLF4J loads log implementation classes from different vendors.

Spring

In SSpring, SPI is widely used, for example: Servlet3.0 specification implements ServletContainerInitializer, automatic type conversion TypeConversionSPI (ConverterSPI, FormatterSPI) and so on.

What collection classes are there in Java?

Collections in Java are mainly divided into four categories:

1. List: ordered, repeatable;

2. Queue: ordered and repeatable;

3. Set: non-repeatable;

4. Map: unordered, with unique keys and non-unique values.

The above is the detailed content of What is Java's SPI?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete