How does java SPI define an interface
This article mainly introduces the relevant knowledge of java SPI how to define the interface, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe you will gain something after reading this article on how to define the interface in java SPI. Let's take a look.
instructions
After the service provider provides the specific implementation of the interface, create a file named with the fully qualified name of the interface in the META-INF/services directory of the jar package, which is the fully qualified name of the implementation class.
1. The jar package of the interface implementation class is placed in the classpath of the main program. The main program dynamically loads the implementation module through java.util.ServiceLoder, finds the fully qualified name of the implementation class by scanning the configuration file in the META-INF/services directory, and loads the class into JVM.
2. The implementation class of SPI must carry a structure method without parameters.
Example
Public interface IShout {void shout ();} public class Cat implements IShout {@ Override public void shout () {System.out.println ("miao miao");}} public class Dog implements IShout {@ Override public void shout () {System.out.println ("wang wang");}} this is the end of the article on "how java SPI defines interfaces". Thank you for reading! I believe you all have a certain understanding of the knowledge of "how to define the interface of java SPI". If you want to learn more, you are welcome to follow the industry information channel.