Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the usage scenario of java SPI?

Shulou Source: shulou.com Published: 2022-05-31 17:50:37 11月11日 Update

In this article, the editor introduces "what is the use scene of java SPI" in detail, the content is detailed, the steps are clear, and the details are handled properly. I hope this article "what is the use scene of java SPI" can help you solve your doubts.

Concept

1. SPI is the service providing interface, and JDK's built-in service 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 agreement of Java SPI

When you are under classpath, create a file named after the service interface in the META-INF/services/ directory under classpath. This file is the specific implementation category that implements the service interface.

When the 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 changes the implementation strategy of the framework according to the needs of actual use.

Common examples:

The database driver loading interface implements class loading.

JDBC loads drive different types of databases.

The logging interface implements class loading.

SLF4J loads log implementation categories from different vendors.

Spring

In SSpring, SPI is widely used, such as Servlet3.0 specification to implement ServletContainerInitializer, automatic type conversion TypeConversionSPI (ConverterSPI,FormatterSPI) and so on.

What are the basic data types of java? the basic data types of Java are as follows:

1. Integer type, which is used to represent the data type of integer.

2. Floating point type, which is used to represent the data type of decimals.

3. Character type. The keyword of character type is "char".

4. Boolean type, which is the basic data type that represents logical values.

After reading this, the article "what is the usage scenario of java SPI" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, please follow the industry information channel.

Tags: Types data services scenarios files articles categories differences content characters interfaces databases integers logs frames modules interfaces drivers propriety examples Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS OPPO Reno Huawei Redmi Shulou Tech Info