CN112685020A - Method and device for dynamically creating service interface, electronic equipment and storage medium - Google Patents

Method and device for dynamically creating service interface, electronic equipment and storage medium Download PDF

Info

Publication number
CN112685020A
CN112685020A CN202011548127.9A CN202011548127A CN112685020A CN 112685020 A CN112685020 A CN 112685020A CN 202011548127 A CN202011548127 A CN 202011548127A CN 112685020 A CN112685020 A CN 112685020A
Authority
CN
China
Prior art keywords
service
interface
spi
special
class
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202011548127.9A
Other languages
Chinese (zh)
Inventor
冯宇婷
班学东
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
JD Digital Technology Holdings Co Ltd
Original Assignee
JD Digital Technology Holdings Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by JD Digital Technology Holdings Co Ltd filed Critical JD Digital Technology Holdings Co Ltd
Priority to CN202011548127.9A priority Critical patent/CN112685020A/en
Publication of CN112685020A publication Critical patent/CN112685020A/en
Pending legal-status Critical Current

Links

Images

Abstract

The invention provides a method, a device, electronic equipment and a storage medium for dynamically creating a service interface, belonging to the technical field of computers, wherein the method comprises the steps of obtaining a service type through interface adaptation based on a Service Providing Interface (SPI) mechanism, wherein the service type comprises a standard service and a special service; when a special service is acquired, loading a path of the special service through an interface file of the SPI, and registering an extension class of the special service to a Spring frame to realize dynamic establishment of a service interface, wherein the extension class of the special service is established through the SPI; and directly calling the special service through the dynamic creation service interface to ensure the normal circulation of the system service flow. The invention can dynamically access the service interface and realize the service function of calling special service without influencing the prior service flow by combining the SPI and the Spring framework.

Description

Method and device for dynamically creating service interface, electronic equipment and storage medium
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a method and an apparatus for dynamically creating a service interface, an electronic device, and a storage medium.
Background
The insurance broker agent is mainly responsible for selling various insurance products, and the sold product channel generally comes from insurance companies or other operating agencies, and the problem of incompatible service interfaces can be encountered in the aspects of special business types such as underwriting, renewal, claim settlement and the like in the face of various different insurance companies and agencies.
Therefore, on the basis of being compatible with the differences of various insurance services, an adaptive scheme of the extensible service interface for accessing the special service is provided, namely, the technical problem which needs to be solved at present is to ensure that the service interface can be dynamically accessed to realize the service function of calling the special service without influencing the existing service flow.
Disclosure of Invention
The invention provides a method, a device, electronic equipment and a storage medium for dynamically creating a service interface, which are used for solving the problem that service interfaces of special service types such as underwriting, renewal, claim settlement and the like are incompatible in the prior art, and can dynamically access the service interface and realize the service function of calling special services without influencing the existing service flow.
The invention provides a method for dynamically creating a service interface, which comprises the following steps:
acquiring a service type through interface adaptation based on a Service Providing Interface (SPI) mechanism, wherein the service type comprises a standard service and a special service;
when a special service is acquired, loading a path of the special service through an interface file of the SPI, and registering an extension class of the special service to a Spring frame to realize dynamic establishment of a service interface, wherein the extension class of the special service is established through the SPI;
and directly calling the special service through the dynamic creation service interface to ensure the normal circulation of the system service flow.
The invention provides a method for dynamically creating a service interface, which is used for acquiring a service type through interface adaptation based on an SPI mechanism, and comprises the following steps:
when the standard service is acquired through interface adaptation based on an SPI mechanism, the standard service is directly called by a calling party through a standard service interface provided by the interface adaptation.
According to the method for dynamically creating the service interface provided by the invention, when a special service is obtained, a path for loading the special service through the interface file of the SPI comprises the following steps:
loading an interface file under the META-INF directory of the SPI;
and loading an absolute path of the special service through the interface file, wherein the absolute path is a directory path based on a web site root directory as a reference.
According to the method for dynamically creating the service interface provided by the present invention, the registering the extension class of the special service to the Spring framework to realize the dynamic creation of the service interface includes:
discovering the service of the special service through a loading path and recording an extension class for realizing the service;
the service loader of the SPI encapsulates the extension class in an iterator object to provide specific service realization for a service provider;
and when the extension class is loaded into the iterator, registering the extension class into the Spring framework, so that the extension class becomes a Bean of Spring.
According to the method for dynamically creating the service interface provided by the present invention, the registering the extension class of the special service to the Spring framework to realize the dynamic creation of the service interface includes:
converting the service type of the special service into a corresponding extension class in a self-defined manner, wherein the service type comprises one or more combinations of suppliers, distributors, product categories and product codes;
registering the corresponding extension class to the Spring framework, and managing the life cycle of the extension class by the Spring framework;
and dynamically creating a corresponding service interface according to the corresponding extension class so as to load the extension class of the Spring framework based on an SPI mechanism.
The method for dynamically creating the service interface provided by the invention directly calls the special service through the dynamically created service interface to ensure the normal circulation of the system service flow, and comprises the following steps:
the caller directly calls the extension class of the Spring frame through the dynamic establishment service interface based on the self-defined SPI;
and the extension class of the Spring framework directly acquires the special service provided by the service provider.
According to the method for dynamically creating the service interface provided by the invention, the ServiceLoader of the SPI encapsulates the extension class in the iterator object to provide specific service realization for the service provider, and the method comprises the following steps:
creating a thread object of a ServiceLoader class to obtain a context class loader, wherein the loader is used for loading the extension class;
and dynamically loading the extension class through the ServiceLoader, and storing the path of the extension class into a configuration file.
The invention also provides a device for dynamically creating the service interface, which comprises:
the acquisition module is used for acquiring the service types through interface adaptation based on an SPI mechanism, wherein the service types comprise standard services and special services;
the dynamic creation module is used for loading a path of a special service through an interface file of the SPI when the special service is obtained, and registering an extension class of the special service to a Spring framework to realize dynamic creation of a service interface, wherein the extension class of the special service is created through the SPI;
and the calling module is used for directly calling the special service through the dynamic creation service interface so as to ensure the normal circulation of the system service flow.
The present invention also provides an electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor implements the steps of the method for dynamically creating a service interface as described in any of the above when executing the program.
The invention also provides a non-transitory computer readable storage medium having stored thereon a computer program which, when executed by a processor, performs the steps of the method of dynamically creating a service interface as described in any of the above.
The method, the device, the electronic equipment and the storage medium for dynamically creating the service interface are used for solving the problem that service interfaces of special service types such as underwriting, renewal and claim settlement are incompatible in the prior art, and by combining the SPI and the Spring framework, the service interface can be dynamically accessed and the service function of calling special services can be realized without influencing the existing service flow.
Drawings
In order to more clearly illustrate the technical solutions of the present invention or the prior art, the drawings needed for the description of the embodiments or the prior art will be briefly described below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and those skilled in the art can also obtain other drawings according to the drawings without creative efforts.
FIG. 1 is a flow diagram of a business application provided by the present invention;
FIG. 2 is a schematic diagram of the invocation service based on SPI mechanism provided by the present invention
FIG. 3 is a schematic flow chart of a dynamic creation service interface provided by the present invention;
FIG. 4 is a schematic flow chart of registering an extension class in a Spring framework according to the present invention;
FIG. 5 is a flow diagram of an extended class encapsulation on an iterator object provided by the present invention;
FIG. 6 is a flow diagram illustrating a specific service invocation provided by the present invention;
FIG. 7 is a schematic structural diagram of an apparatus for dynamically creating a service interface provided in the present invention;
fig. 8 is a schematic structural diagram of an electronic device provided in the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention clearer, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings, and it is obvious that the described embodiments are some, but not all embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Technical terms of the method, the apparatus, the electronic device, and the storage medium for dynamically creating the service interface according to the present invention are described below.
JAVA is a door-to-object programming language that can write desktop applications, Web applications, distributed system and embedded system applications. The JAVA language absorbs various advantages of the C + + language, and has two features of powerful function and simplicity and easy use. Furthermore, the JAVA language, which is a representative of the static object-oriented programming language, implements an object-oriented theory, allowing programmers to perform complex programming in an elegant thinking manner. Furthermore, the JAVA language has the characteristics of simplicity, object-oriented property, distribution, safety, platform independence and portability, dynamicity and the like.
The SPI (english: Service Provider Interface, chinese: Service providing Interface) is a set of JAVA-provided technical systems for third party implementation or extended use, and is also a Service providing (Interface implementation) discovery mechanism built in JDK (JAVA Development Kit, JAVA Development tool), and can search for files and load classes defined therein through META-INF/Service files under the ClassPath path. Therefore, SPI is a specification built under interface-oriented programming for extensible or dynamically changing implementation of components. The SPI may be used to enable the framework expansion and replacement components, for example, in the most common database connection JDBC, java. Therefore, the SPI mechanism of JAVA can search service implementation for a certain service interface, and by decoupling specific implementation and service use of the service, the expandability of a program is greatly enhanced, and the program can be plugged and unplugged.
The Spring framework is an open source J2EE application framework and is a lightweight container for managing the lifecycle of beans. The beans are objects managed by the Spring framework, and can be one or more, and the application programs are formed by the beans.
Because SPI does not combine together with the Spring frame among the prior art, so no matter be Java SPI or Spring SPI, can't realize with the integration of Spring frame, lead to when calling the Spring frame and quoting extension class, can't find specific extension class.
Based on the above, when the method is applied to the field of insurance services, when the existing technical architecture receives various insurance services (such as underwriting, renewal and claim settlement), since each service type of the insurance services belongs to different third parties, a caller cannot call the services of the insurance services provided by a service provider due to different service interface specifications when accessing the insurance services.
Therefore, the invention provides a method, a device, electronic equipment and a storage medium for dynamically creating a service interface, which are used for solving the problem that service interfaces of special service types such as underwriting, renewal, claim settlement and the like are incompatible in the prior art, and by combining the SPI and the Spring framework, the service interface can be dynamically accessed and the service function of calling special services can be realized without influencing the existing service flow.
The method, apparatus, electronic device and storage medium for dynamically creating a service interface according to the present invention are described below with reference to fig. 1 to 8.
Fig. 1 is a schematic flow chart of a service application provided by the present invention, as shown in the figure.
Step 100, a client acquires a service purchased by a user, wherein the service may be an insurance service or other services.
Step 101, a client acquires that a user performs business type operation, wherein the business type includes operations of underwriting, renewal, claims settlement and the like on the purchased insurance service.
Step 102, an interface of the system is adapted to obtain the service type operation of the user, and firstly, whether the service type is a standard service or a special service is judged.
Step 103, if the service type is a standard service, the standard service is a standard service interface of the system technical architecture, which can be directly called, and step 105 is executed.
Step 104, if the service type is a special service, that is, the special service is incompatible with the interface of the technical architecture of the system, because different database manufacturers implement different service interfaces, the special service cannot be directly called, and the technical framework extension needs to be performed on the service, and step 106 is executed.
And 105, calling the standard service by calling a standard service interface, namely calling the standard service by using the existing SPI implementation class.
And step 106, realizing the frame expansion frame step. Optionally, pluggable service extension is implemented by combining SPI with Sring.
And 107-109, establishing a service interface specification according to the process of special business, such as dimensions of suppliers, distributors, product types, product codes and the like.
And step 110, the caller calls the special service of the service provider through the dynamic creation service interface so as to realize the normal circulation of the system service flow.
Fig. 1 shows an application scenario of the present invention, that is, aiming at the field of selling insurance by an operation agency platform, the present invention can plug in and pull out a service interface at key service points such as underwriting, renewal, and claim settlement in insurance services in order to face diversified access service types of different insurance companies and different insurance products, so as to show product characteristics of the insurance products.
The extensible adaptation scheme based on the dynamic establishment of the service interface ensures that the product characteristics of special services can be realized by seamlessly accessing the service interface without influencing the existing process, the special services are adapted and transversely extended through the service discovery SPI, interface specifications can be formulated in different dimensions (such as dimensions of suppliers, distributors, product categories, product codes and the like), and the normal circulation of the system service process is ensured.
The steps of expanding the framework in step 106 will be described below from a technical implementation level.
FIG. 2 is a schematic diagram of the SPI mechanism based call service provided by the present invention, as shown.
For standard services: the caller 200 calls the standard service interface 201, and after the service discovery SPI performs service loading, the caller directly calls the implementation class a corresponding to the service provider 202, thereby implementing service calling of the standard service.
It should be noted that the definition of the SPI interface is that the caller, and after the service provider provides an implementation of the interface, a file named as the service interface needs to be created in META-INF/services/directory under classpath, and the content in the file is the specific implementation class of the interface. When other programs need the service, the configuration file in the META-INF/services of the jar packet (generally, the jar packet is used as a dependency) can be searched, the configuration file has a specific implementation class name of an interface, loading and instantiation can be carried out according to the class name, and the service can be used. The tool classes for lookup service implementation in JDK (JAVA development tool) are: java.util.serviceloader.
Aiming at special services: the caller calls the extended service interface N203 by adopting the interface adaptation scheme of the invention, the service discovery SPI can customize the extension class of the SPI204 about the special service, and registers the extension class in the Spring frame 205, thus realizing the combination 206 of the SPI and the Spring frame, and calling the extension class C of the service provider 202 through the extended service interface N203 when the service discovery is carried out. The extended service interface is a service interface dynamically created by the SPI, and may be one or more service interfaces, and is specifically set according to a class of a special service, where the class is a service content of the special service.
It can be understood that the SPI does not know how to implement an interface of a data packet of a service provider, and needs to extend a class, that is, configure the extended class into a file, where the file name is an interface that needs to be extended, and then call the ServiceLoader loading interface, so as to obtain an instance of the extended class. The ServiceLoader is a set of SPI framework provided by Java and is used for realizing decoupling of a service provider and a service user.
In summary, the standard service class has a corresponding implementation class in the Spring framework, so the SPI can be directly called. However, the class of the special service has no corresponding implementation class in the Spring framework, so the SPI cannot be directly called, and the extension class defined by the SPI needs to be registered in the Spring framework, so that the extension class can be directly called by the SPI.
FIG. 3 is a flow diagram of a dynamic creation service interface provided by the present invention, as shown. A method of dynamically creating a service interface, comprising:
and step 300, the caller acquires the service types through interface adaptation based on an SPI mechanism, wherein the service types comprise standard services and special services.
Optionally, different insurance companies provide different services, and the services of each insurance company are maintained by respective research and development teams, so that under a unified service platform, if the services provided by different insurance companies need to be called, a dynamic service interface needs to be created, that is, a service interface specification is formulated. Since the SPI (service discovery) mechanism provides a uniform service type service interface and supports pluggable service extension, the dynamic service can be acquired by adopting the SPI mechanism.
Optionally, when a special service is acquired, loading an absolute path of the special service through the interface file of the SPI includes:
and loading an interface file under the META-INF directory of the SPI.
Alternatively, the JAVA program is compiled into an exe file, which typically includes an executable JAR package. The JAR file package is a ZIP compressed archive of class files, each JAR file has a default generated META-INF directory, and the META-INF is equivalent to an information package and used for configuring an application program, an extension program, a class loader and the like.
And loading an absolute path of the special service through the interface file, wherein the absolute path is a directory path based on a web site root directory as a reference.
Step 301, when a calling party acquires a special service, loading a path of the special service through an interface file of the SPI, and registering an extension class of the special service to a Spring framework to implement dynamic creation of a service interface, where the extension class of the special service is created through the SPI.
In the prior art, both Java SPI and Spring SPI are integrated with a Spring container. For example, if the special service a is created in the SPI, an error may occur if the special service a implementation class calls the specific content corresponding to the special service a managed by the Spring frame, and since the life cycle of the special service a implementation class is not handed to the Spring frame for management, the specific content corresponding to the special service a of the Spring frame cannot be called.
Therefore, the invention introduces the service logic of the self-defined SPI, namely, the SPI interface file is loaded, the self-defined extension class Bean is registered in the Spring framework through the interface file, and the Spring manages the extension class Bean.
It should be noted that each SPI service interface has a service file, and the name of the service file is a full path of class names for implementing a canonical interface. The specific implementation class of the specification depends on the service interface of the specification.
Step 302, the caller directly calls the special service of the service provider through the dynamic creation service interface to ensure the normal circulation of the system service flow.
The invention realizes the logic of self-defining dynamic Bean loading to the Spring frame based on the SPI mechanism, so the special service is directly called through the dynamic establishing service interface to ensure the normal circulation of the system service flow.
The service logic of the SPI in combination with Spring will be explained by the following specific embodiments and the accompanying drawings.
Fig. 4 is a schematic flowchart of registering an extension class in a Spring framework according to the present invention, as shown in the figure. The registering the extension class of the special service to a Spring framework to realize dynamic creation of a service interface includes:
step 400, discovering the service of the special service through the loading path and recording the extension class for realizing the service.
Optionally, the service interface is extended according to the dimension of the special service. For example, if the special service is a renewal service of an insurance service, the service interface specification can be made from dimensions of suppliers, product categories, product codes and the like.
Step 401, the ServiceLoader of the SPI encapsulates the extension class in the iterator object, and provides specific service implementation for the service provider.
The ServiceLoader is a loader for loading files under the fixed class path, and the implementation class corresponding to the service interface statement is loaded through the ServiceLoader.
Optionally, the present invention implements dynamic creation of the service interface in a manner of re-ServiceLoader. The execution step of the re-ServiceLoader comprises the following steps: defining a service interface, realizing the service interface, registering the realization class to META-INF/services and loading service.
Iterating is a commonality of all set classes under the JAVA set framework, that is, all elements in the set are traversed once, and an iterator object is required to be relied on in the iteration process. Iterator (Iterator) mode, also called cursor mode, provides a way to access individual elements in a container (the collection class of the collection framework in JAVA is called container) object without exposing the internal details of the object.
Step 402, when the extension class is loaded into the iterator, the extension class is registered in the Spring framework, so that the extension class becomes a Bean of Spring.
Optionally, the present invention may dynamically generate beans according to the special service information of the service type, specifically: under the self-defined SPI, the realization of the service interface is generated by the SPI framework, and the extension class defined by the SPI framework is dynamically registered in the Spring framework.
FIG. 5 is a flow chart of the extended class encapsulation in the iterator object provided by the present invention. The ServiceLoader of the SPI encapsulates the extension class in an iterator object, and provides specific service implementation for a service provider, including:
step 500, creating a thread object of the ServiceLoader class to obtain a context class loader, where the loader is used to load the extension class.
Optionally, the internal implementation logic of the ServiceLoader class is implemented by obtaining a context loader of the current thread, where the context loader is used for subsequently loading an extension class that implements the service interface, and the dynamic creation of the service interface is implemented in the iterator.
Optionally, a reflection mechanism is used to obtain the class object of the extended class, and the instance of the extended class is obtained through the class object.
Step 501, dynamically loading the extension class through the ServiceLoader, and saving the path of the extension class in a configuration file.
Optionally, the runtime provides specific service logic by transforming the supplier of the insurance service and the product coding dimension down to a specific extension class.
Therefore, the SPI realizes interface-oriented programming through a dynamic loading mechanism, the separation of the frame and the bottom layer is improved, the ServiceLoader is used for loading an extension class, and the extension class is a specific implementation class for realizing the dynamic establishment of the service interface.
Fig. 6 is a schematic flow chart of invoking a special service provided by the present invention, as shown in the figure. The directly calling the special service through the dynamic creation service interface to ensure the normal circulation of the system service process comprises the following steps:
and step 600, the caller directly calls the extension class of the Spring frame through the dynamic creation service interface based on the self-defined SPI.
Step 601, the extension class of the Spring framework directly obtains the service of the special service provided by the service provider.
In summary, by combining the SPI and the Spring framework, a dynamic service interface can be created, and when the special service is called by the dynamic service interface, the system can run the code of the special service, and can obtain the service content of the special service.
The following describes a device for dynamically creating a service interface according to the present invention, and the device for dynamically creating a service interface described below and the method for dynamically creating a service described above may be referred to correspondingly.
Fig. 7 is a schematic structural diagram of an apparatus for dynamically creating a service interface provided in the present invention, as shown in the figure. An apparatus 700 for dynamically creating a service interface includes an obtaining module 701, a dynamic creating module 702, and a calling module 703. Wherein the content of the first and second substances,
an obtaining module 701, configured to obtain a service type through interface adaptation based on an SPI mechanism, where the service type includes a standard service and a special service.
A dynamic creation module 702, configured to, when a special service is obtained, load a path of the special service through an interface file of the SPI, and register an extension class of the special service in a Spring framework to implement dynamic creation of a service interface, where the extension class of the special service is created through the SPI.
The invoking module 703 is configured to directly invoke the special service through the dynamic creation service interface to ensure normal flow of a system service flow.
Fig. 8 illustrates a physical structure diagram of an electronic device, and as shown in fig. 8, the electronic device may include: a processor (processor)810, a communication Interface 820, a memory 830 and a communication bus 840, wherein the processor 810, the communication Interface 820 and the memory 830 communicate with each other via the communication bus 840. The processor 810 may call logic instructions in the memory 830 to perform the steps of the above-described method for dynamically creating a service interface, the method comprising:
acquiring a service type through interface adaptation based on an SPI mechanism, wherein the service type comprises a standard service and a special service;
when a special service is acquired, loading a path of the special service through an interface file of the SPI, and registering an extension class of the special service to a Spring frame to realize dynamic establishment of a service interface, wherein the extension class of the special service is established through the SPI;
and directly calling the special service through the dynamic creation service interface to ensure the normal circulation of the system service flow.
In addition, the logic instructions in the memory 830 may be implemented in software functional units and stored in a computer readable storage medium when the logic instructions are sold or used as independent products. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
In another aspect, the present invention also provides a computer program product comprising a computer program stored on a non-transitory computer-readable storage medium, the computer program comprising program instructions which, when executed by a computer, enable the computer to perform the steps of the method for dynamically creating a service interface provided by the above methods, the method comprising:
acquiring a service type through interface adaptation based on an SPI mechanism, wherein the service type comprises a standard service and a special service;
when a special service is acquired, loading a path of the special service through an interface file of the SPI, and registering an extension class of the special service to a Spring frame to realize dynamic establishment of a service interface, wherein the extension class of the special service is established through the SPI;
and directly calling the special service through the dynamic creation service interface to ensure the normal circulation of the system service flow.
In yet another aspect, the present invention also provides a non-transitory computer readable storage medium having stored thereon a computer program which, when executed by a processor, performs the steps of the method for dynamically creating a service interface provided above, the method comprising:
acquiring a service type through interface adaptation based on an SPI mechanism, wherein the service type comprises a standard service and a special service;
when a special service is acquired, loading a path of the special service through an interface file of the SPI, and registering an extension class of the special service to a Spring frame to realize dynamic establishment of a service interface, wherein the extension class of the special service is established through the SPI;
and directly calling the special service through the dynamic creation service interface to ensure the normal circulation of the system service flow.
The above-described embodiments of the apparatus are merely illustrative, and the units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment. One of ordinary skill in the art can understand and implement it without inventive effort.
Through the above description of the embodiments, those skilled in the art will clearly understand that each embodiment can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware. With this understanding in mind, the above-described technical solutions may be embodied in the form of a software product, which can be stored in a computer-readable storage medium such as ROM/RAM, magnetic disk, optical disk, etc., and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the methods described in the embodiments or some parts of the embodiments.
Finally, it should be noted that: the above examples are only intended to illustrate the technical solution of the present invention, but not to limit it; although the present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and such modifications or substitutions do not depart from the spirit and scope of the corresponding technical solutions of the embodiments of the present invention.

Claims (10)

1. A method for dynamically creating a service interface, comprising:
acquiring a service type through interface adaptation based on a Service Providing Interface (SPI) mechanism, wherein the service type comprises a standard service and a special service;
when a special service is acquired, loading a path of the special service through an interface file of the SPI, and registering an extension class of the special service to a Spring frame to realize dynamic establishment of a service interface, wherein the extension class of the special service is established through the SPI;
and directly calling the special service through the dynamic creation service interface to ensure the normal circulation of the system service flow.
2. The method of claim 1, wherein the obtaining the traffic type through interface adaptation based on the SPI mechanism comprises:
when the standard service is acquired through interface adaptation based on an SPI mechanism, the standard service is directly called by a calling party through a standard service interface provided by the interface adaptation.
3. The method according to claim 1, wherein the loading a path of a special service through an interface file of the SPI when the special service is acquired comprises:
loading an interface file under the META-INF directory of the SPI;
and loading an absolute path of the special service through the interface file, wherein the absolute path is a directory path based on a web site root directory as a reference.
4. The method for dynamically creating a service interface according to claim 1, wherein the registering the extended class of the special service to a Spring framework to implement dynamically creating a service interface comprises:
discovering the service of the special service through a loading path and recording an extension class for realizing the service;
the service loader of the SPI encapsulates the extension class in an iterator object to provide specific service realization for a service provider;
and when the extension class is loaded into the iterator, registering the extension class into the Spring framework, so that the extension class becomes a Bean of Spring.
5. The method according to claim 4, wherein the ServiceLoader of the SPI encapsulates the extension class in an iterator object to provide specific service implementation for a service provider, and comprises:
creating a thread object of a ServiceLoader class to obtain a context class loader, wherein the loader is used for loading the extension class;
and dynamically loading the extension class through the ServiceLoader, and storing the path of the extension class into a configuration file.
6. The method for dynamically creating a service interface according to claim 1, wherein the registering the extended class of the special service to a Spring framework to implement dynamically creating a service interface comprises:
converting the service type of the special service into a corresponding extension class in a self-defined manner, wherein the service type comprises one or more combinations of suppliers, distributors, product categories and product codes;
registering the corresponding extension class to the Spring framework, and managing the life cycle of the extension class by the Spring framework;
and dynamically creating a corresponding service interface according to the corresponding extension class so as to load the extension class of the Spring framework based on an SPI mechanism.
7. The method according to claim 1, wherein said directly invoking said special service through said dynamically created service interface to ensure normal flow of system service flow comprises:
directly calling the extension class of the Spring framework through the dynamic establishment service interface based on the self-defined SPI;
and the extension class of the Spring framework directly acquires the special service provided by the service provider.
8. An apparatus for dynamically creating a service interface, comprising:
the acquisition module is used for acquiring the service types through interface adaptation based on an SPI mechanism, wherein the service types comprise standard services and special services;
the dynamic creation module is used for loading a path of a special service through an interface file of the SPI when the special service is obtained, and registering an extension class of the special service to a Spring framework to realize dynamic creation of a service interface, wherein the extension class of the special service is created through the SPI;
and the calling module is used for directly calling the special service through the dynamic creation service interface so as to ensure the normal circulation of the system service flow.
9. An electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the steps of the method of dynamically creating a service interface according to any of claims 1 to 7 are implemented when the program is executed by the processor.
10. A non-transitory computer readable storage medium having stored thereon a computer program, wherein the computer program, when executed by a processor, implements the steps of the method of dynamically creating a service interface as claimed in any one of claims 1 to 7.
CN202011548127.9A 2020-12-24 2020-12-24 Method and device for dynamically creating service interface, electronic equipment and storage medium Pending CN112685020A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011548127.9A CN112685020A (en) 2020-12-24 2020-12-24 Method and device for dynamically creating service interface, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011548127.9A CN112685020A (en) 2020-12-24 2020-12-24 Method and device for dynamically creating service interface, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN112685020A true CN112685020A (en) 2021-04-20

Family

ID=75451912

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011548127.9A Pending CN112685020A (en) 2020-12-24 2020-12-24 Method and device for dynamically creating service interface, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN112685020A (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113434315A (en) * 2021-07-07 2021-09-24 京东科技控股股份有限公司 Interface management method and device, storage medium and electronic equipment
CN114363169A (en) * 2021-12-27 2022-04-15 紫光云(南京)数字技术有限公司 Device auditing method based on SPI
CN117312222A (en) * 2023-11-29 2023-12-29 博思数采科技股份有限公司 SPI-based government purchasing method, system, equipment and medium

Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6275983B1 (en) * 1993-07-19 2001-08-14 Object Technology Licensing Corp. Object-oriented operating system
US20120179503A1 (en) * 2010-05-12 2012-07-12 Winshuttle, Llc Dynamic web services work flow system and method
CN103258159A (en) * 2011-12-16 2013-08-21 德商赛克公司 Extensible and/or distributed authorization system and/or methods of providing the same
US20140280484A1 (en) * 2013-03-15 2014-09-18 Oliver Klemenz Dynamic Service Extension Infrastructure For Cloud Platforms
US20140344792A1 (en) * 2013-05-16 2014-11-20 Sap Ag Dynamic bytecode modification of classes and class hierarchies
US20170003960A1 (en) * 2015-01-30 2017-01-05 Oracle International Corporation System and method for automatic porting of software applications into a cloud computing environment
CN109710428A (en) * 2018-12-27 2019-05-03 杭州数梦工场科技有限公司 A kind of dynamic call method and device for realizing class
CN110245030A (en) * 2019-05-29 2019-09-17 北京字节跳动网络技术有限公司 A kind of data service providing method, device, medium and electronic equipment
CN110955543A (en) * 2019-12-12 2020-04-03 浙江大搜车软件技术有限公司 Service processing method, device, equipment and computer readable storage medium

Patent Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6275983B1 (en) * 1993-07-19 2001-08-14 Object Technology Licensing Corp. Object-oriented operating system
US20120179503A1 (en) * 2010-05-12 2012-07-12 Winshuttle, Llc Dynamic web services work flow system and method
CN103258159A (en) * 2011-12-16 2013-08-21 德商赛克公司 Extensible and/or distributed authorization system and/or methods of providing the same
US20140280484A1 (en) * 2013-03-15 2014-09-18 Oliver Klemenz Dynamic Service Extension Infrastructure For Cloud Platforms
US20140344792A1 (en) * 2013-05-16 2014-11-20 Sap Ag Dynamic bytecode modification of classes and class hierarchies
US20170003960A1 (en) * 2015-01-30 2017-01-05 Oracle International Corporation System and method for automatic porting of software applications into a cloud computing environment
CN109710428A (en) * 2018-12-27 2019-05-03 杭州数梦工场科技有限公司 A kind of dynamic call method and device for realizing class
CN110245030A (en) * 2019-05-29 2019-09-17 北京字节跳动网络技术有限公司 A kind of data service providing method, device, medium and electronic equipment
CN110955543A (en) * 2019-12-12 2020-04-03 浙江大搜车软件技术有限公司 Service processing method, device, equipment and computer readable storage medium

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113434315A (en) * 2021-07-07 2021-09-24 京东科技控股股份有限公司 Interface management method and device, storage medium and electronic equipment
CN114363169A (en) * 2021-12-27 2022-04-15 紫光云(南京)数字技术有限公司 Device auditing method based on SPI
CN114363169B (en) * 2021-12-27 2023-10-27 紫光云(南京)数字技术有限公司 SPI-based equipment auditing method
CN117312222A (en) * 2023-11-29 2023-12-29 博思数采科技股份有限公司 SPI-based government purchasing method, system, equipment and medium

Similar Documents

Publication Publication Date Title
CN100492290C (en) Method for acquiring and converting the state of component in the time of operation during software dynamic evolvement
US9934005B2 (en) Dynamically building locale objects or subsections of locale objects based on historical data
US10719386B2 (en) Method for fault handling in a distributed it environment
US8020146B2 (en) Applying deferred refactoring and API changes in an IDE
CN112685020A (en) Method and device for dynamically creating service interface, electronic equipment and storage medium
US11552955B2 (en) Data security across data residency restriction boundaries
US20070168926A1 (en) Software customization framework
US20120110545A1 (en) Abstracting transformation for model driven architecture
US7984456B2 (en) Interceptor framework using java dynamic proxies
US10379914B2 (en) System and method for achieving specific behaviors by intercepting file access calls in a mainframe rehosting platform
CN106569880B (en) Method and system for dynamically sharing resources between Android applications
JP2011516987A (en) Method and apparatus for managing mobile device software
CN101727475B (en) Method, device and system for acquiring database access process
US6658644B1 (en) Services-based architecture for a telecommunications enterprise
US8738746B2 (en) Configuration management for real-time server
US7490077B2 (en) Extensible dependency management framework and method
US9665352B2 (en) COBOL reference architecture
US11080102B2 (en) System and method for developing modularized application
CN111813836A (en) Method for improving Ethereum block chain system expansibility
CN114416202B (en) Mobile terminal SDK calling method and system
US20060129560A1 (en) Architecture for enabling business components to access middleware application programming interfaces (APIs) in a runtime environment
CN113626001A (en) API dynamic editing method and device based on script
CN113867776A (en) Method and device for publishing middle station application, electronic equipment and storage medium
Srinivasmurthy et al. Web2exchange: A model-based service transformation and integration environment
Gschwind Automated adaptation of component interfaces with type based adaptation

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
CB02 Change of applicant information
CB02 Change of applicant information

Address after: Room 221, 2 / F, block C, 18 Kechuang 11th Street, Daxing District, Beijing, 100176

Applicant after: Jingdong Technology Holding Co.,Ltd.

Address before: Room 221, 2 / F, block C, 18 Kechuang 11th Street, Daxing District, Beijing, 100176

Applicant before: Jingdong Digital Technology Holding Co., Ltd