Multi-tenant Class method and device based on Spring father-son container hot loading

The method and device for hot loading multi-tenants using Spring parent-child containers address the inefficiencies in Spring frameworks by packaging tenant-specific logic into independent jar files and using separate class loaders, enabling seamless application updates without server restarts, thus enhancing deployment speed and reducing maintenance time.

CN119088428APending Publication Date: 2024-12-06CHINA CITIC BANK CO LTD
View PDF 0 Cites 3 Cited by

Patent Information

Application Number
CN202411023520.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-29
Publication Date
2024-12-06

AI Technical Summary

Technical Problem

Existing Spring frameworks lack hot loading capability, leading to inefficient application updates and deployment processes, which are either complex or reduce deployment speed when third-party solutions are integrated.

Method used

Implement a method and device for hot loading multi-tenants using Spring parent-child containers, where tenant-specific logic is packaged into independent jar files, managed by separate class loaders, and Beans are routed based on TenantScope annotations, allowing dynamic updates without server restarts.

Benefits of technology

Enables dynamic application logic updates without server restarts, improving update and deployment speed while ensuring consistency and security, and reducing R&D and maintenance time.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119088428A_ABST
    Figure CN119088428A_ABST
Patent Text Reader

Abstract

The invention discloses a Class method for hot loading of multiple tenants based on Spring father and son containers, which comprises the following steps: setting a configuration source for an application to store tenant information, and creating and configuring a tenant specific son container when the application runs; packaging the personalized logic of each tenant into an independent jar file, and independently updating and deploying the independent jar file independent of the general logic; distributing an independent class loader for the tenant, wherein the class loader is used for loading a jar file specific to the tenant; creating Spring sub-containers for the tenants, and loading and initializing specific Bean of the tenants by class loaders corresponding to the Spring sub-containers; a Tenant Scope annotation is self-defined to distinguish the Bean of the instance; the annotated Bean is automatically routed to the Spring sub-container of the tenant to obtain the Bean; when the personalized jar of the tenant is upgraded and updated, the Spring parent container creates a new Spring sub-container for the tenant, the Class in the new jar is loaded, the old sub-container is closed, and resources are released. Through the technical scheme, the application logic can be dynamically updated without restarting the server, the updating online speed of the application is improved, and the research and development and operation and maintenance time is saved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer science and technology, in particular to Spring application design in a multi-tenant application scenario, and more particularly to a method and device for hot loading a multi-tenant Class based on a Spring parent-child container. Background Art

[0002] Spring is an open source framework for simplifying enterprise-level Java application development. It provides data access, web support, messaging and other functions, and integrates with multiple technology stacks and frameworks. The emergence of Spring improves development efficiency and reduces maintenance costs, making it an ideal choice for building high-quality applications.

[0003] However, Spring does not have the hot loading capability, which means that the code or configuration can be dynamically loaded and updated while the application is running without restarting the entire application. In this way, only the new code or configuration needs to be replaced or loaded each time an update is made, without the need for tedious packaging and restarting operations, which significantly improves the speed of going online. To this end, the Spring-boot-devtools module provides the ability to automatically apply code changes, which can automatically reload the application when the code changes without manual restart. In addition, there are some third-party hot loading solutions that can also be integrated with the Spring framework. However, these solutions all have certain limitations. The introduction of the Spring-boot-devtools module will bring additional complexity, and it is necessary to ensure the consistency and security of data during the hot loading process. The introduction of some other third-party hot loading solutions will reduce the deployment speed.

[0004] Therefore, how to provide a simple and effective technical solution to dynamically update application logic without restarting the server and improve the update and deployment speed of the application is a technical problem that needs to be solved urgently. Summary of the invention

[0005] To this end, the present application provides a technical solution to solve the above-mentioned existing technical problems, realize dynamic update of application logic without restarting the server, and improve the update and deployment speed of the application. The present invention provides a class method and device for hot loading multi-tenants based on Spring parent-child containers to solve the above-mentioned technical problems.

[0006] To achieve the above objectives, in a first aspect, the present invention provides a Class method for hot loading multiple tenants based on Spring parent-child containers, comprising:

[0007] Initialize the Spring parent container and load the common logic class of the application.

[0008] A configuration source is set for the application to store tenant information, where the information is used to create and configure a tenant-specific sub-container when the application is running.

[0009] The personalized logic of each tenant is packaged into an independent jar file, and the independent jar file is updated and deployed independently of the general logic.

[0010] An independent class loader is allocated to each tenant, and the class loader is used to load the jar file specific to each tenant.

[0011] A Spring subcontainer is created for each tenant, and each tenant-specific Bean is loaded and initialized through the corresponding class loader.

[0012] A custom TenantScope annotation is used to identify beans whose instances need to be distinguished based on the tenant.

[0013] When processing business requests, the requests are intercepted through aspect-oriented programming or other mechanisms, and the Bean requests annotated with TenantScope are routed to the corresponding tenant sub-container according to the tenant information.

[0014] When the new sub-container is created and initialized, the service request is routed to the new sub-container, and the old sub-container is closed, and related resources are released.

[0015] Furthermore, when the tenant accesses the application for the first time, or when the tenant's jar file is updated, the Spring parent container dynamically creates a new child container based on the tenant information. Each new child container will inherit the common bean definition of the parent container and also have its own specific bean configuration.

[0016] Furthermore, the TenantScope annotation is used to identify the beans whose instances need to be distinguished according to the tenant, and also includes: the TenantScope annotation is used to extend the Scope function of Spring, and when these beans are obtained, the correct instance is returned according to the information of the current tenant; for beans with TenantScope annotations, when obtaining beans, the tenant-personalized beans are obtained from the tenant subcontainer according to the tenant number.

[0017] Furthermore, when the tenant's personalized jar is updated, the Spring parent container dynamically creates a new child container and loads the updated jar file by using a new class loader, and the process is performed without interrupting other tenant services.

[0018] In the second aspect, the present invention also provides a Class device for hot loading multiple tenants based on Spring parent-child containers, the device comprising: an initialization unit, a first configuration unit, a second configuration unit, a third configuration unit, a fourth configuration unit, and a custom unit.

[0019] Initialization unit: used to initialize the Spring parent container and load the common logic class of the application.

[0020] A first configuration unit is used to set a configuration source for the application to store tenant information, where the information is used to create and configure a tenant-specific sub-container when the application is running.

[0021] The second configuration unit is used to package the personalized logic of each tenant into an independent jar file, and the independent jar file is updated and deployed independently of the general logic.

[0022] The third configuration unit is used to allocate an independent class loader to each tenant, and the class loader is used to load the jar file specific to each tenant.

[0023] The fourth configuration unit is used to create a Spring subcontainer for each tenant, and load and initialize the specific Bean of each tenant through the corresponding class loader.

[0024] Custom unit: used to customize the TenantScope annotation, which is used to identify the beans whose instances need to be distinguished according to the tenant.

[0025] When processing business requests, the requests are intercepted through aspect-oriented programming or other mechanisms, and the Bean requests annotated with TenantScope are routed to the corresponding tenant sub-container according to the tenant information.

[0026] When the new sub-container is created and initialized, the service request is routed to the new sub-container, and the old sub-container is closed, and related resources are released.

[0027] Furthermore, when the tenant accesses the application for the first time, or when the tenant's jar file is updated, the Spring parent container dynamically creates a new child container based on the tenant information. Each new child container will inherit the common bean definition of the parent container and also have its own specific bean configuration.

[0028] Furthermore, the TenantScope annotation is used to identify the beans whose instances need to be distinguished according to the tenant, and also includes: the TenantScope annotation is used to extend the Scope function of Spring, and when these beans are obtained, the correct instance is returned according to the information of the current tenant; for beans with TenantScope annotations, when obtaining beans, the tenant-personalized beans are obtained from the tenant subcontainer according to the tenant number.

[0029] Furthermore, when the tenant's personalized jar is updated, the Spring parent container dynamically creates a new child container and loads the updated jar file by using a new class loader, and the process is performed without interrupting other tenant services.

[0030] In a third aspect, the present invention provides a computing device, comprising:

[0031] A memory for storing program instructions;

[0032] The processor is used to call the program instructions stored in the memory and execute the above-mentioned Class method based on Spring parent-child container hot loading of multi-tenants according to the obtained program instructions.

[0033] In a fourth aspect, the present invention provides a computer-readable storage medium, including computer-readable instructions. When a computer reads and executes the computer-readable instructions, the above-mentioned Class method for hot loading multiple tenants based on Spring parent-child containers is implemented. The readable medium may be multiple, and the multiple readable media can run independently of each other.

[0034] Compared with the existing technology, this solution stores tenant information by setting up a configuration source for the application, and creates and configures tenant-specific sub-containers when the application is running; packages the personalized logic of each tenant into an independent jar file, and updates and deploys it independently of the general logic; allocates an independent class loader to each tenant to load each tenant-specific jar file; creates a Spring sub-container for each tenant, and uses the corresponding class loader to load and initialize each tenant-specific bean; customizes the TenantScope annotation to identify the beans that need to be distinguished by tenant instance; when processing business requests, the annotated beans are automatically routed to the tenant's Spring sub-container to obtain the beans; when the tenant's personalized jar is upgraded, the Spring parent container creates a new Spring sub-container for the tenant, loads the Class in the new jar, and closes the old sub-container, while releasing related resources. This technical solution can dynamically update the application logic without restarting the server, improve the update and launch speed of the application, and save R&D and operation and maintenance time. BRIEF DESCRIPTION OF THE DRAWINGS

[0035] In order to more clearly illustrate the embodiments of the present disclosure or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present disclosure. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.

[0036] Figure 1 A flow chart of the Class method for hot loading multi-tenants based on Spring parent-child containers provided by the present invention;

[0037] Figure 2 An execution flow framework diagram of an embodiment of the Class method for hot loading multiple tenants based on Spring parent-child containers provided by the present invention;

[0038] Figure 3 A structural block diagram of an embodiment of a Class device for hot loading multiple tenants based on Spring parent-child containers provided by the present invention. DETAILED DESCRIPTION

[0039] The embodiments of the present application are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present application, and cannot be interpreted as limiting the present application.

[0040] It will be understood by those skilled in the art that, unless otherwise stated, the singular forms "a", "an" and "the" used herein may also include plural forms. It should be further understood that the term "comprising" used in the specification of the present application refers to the presence of features, integers, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or groups thereof. The term "and / or" used herein includes all or any unit and all combinations of one or more associated listed items.

[0041] In order to make the objectives, technical solutions and advantages of the present application more clear, the specific implementation methods of the present application will be further described in detail below with reference to the accompanying drawings.

[0042] For the convenience of description, some nouns or terms involved in the embodiments of the present application are explained below:

[0043] First of all, the Spring framework is a framework for managing and organizing application components, and the container is the core part of Spring responsible for creating and managing these components. In Spring, containers can be divided into parent containers and child containers.

[0044] The parent container is an independent container that can contain other containers as child containers. The main function of the parent container is to manage and maintain shared resources, such as database connection pools, thread pools, etc. These shared resources can be accessed and used throughout the application, improving the reusability and efficiency of the code.

[0045] The child container is the direct child container of the parent container. It can inherit all configurations and components in the parent container and can add its own configurations and components. The child container can access the Bean instance and BeanDefinition instance in the parent container, but not vice versa. This design helps to unitize the code, so that each unit (or child container) can focus on its own functions while collaborating with other modules.

[0046] In specific applications, parent-child containers have many application scenarios. For example, in the Spring MVC environment, a common usage is to let the business logic layer (Service) and data access layer (DAO) be managed by the Spring parent container, and the controller layer (Controller) be managed by the Spring MVC child container. This division helps improve the readability and maintainability of the code, making team collaboration smoother.

[0047] The core of the present invention provides a Class method for hot loading multiple tenants based on Spring parent-child containers. Figure 1The figure shows a flow chart of the Class method for hot loading multi-tenants based on Spring parent-child containers provided in this embodiment. In order to better understand the method provided in this embodiment, Figure 1 The technical solution provided in this embodiment is described in detail:

[0048] Step S1: When the application starts, the Spring parent container is initialized and loads all common Bean definitions and Classes.

[0049] Among them, these common beans include basic services, data access layer, common components, etc.

[0050] Step S2: Setting a configuration source for the application to store tenant information, including tenant ID and tenant-specific jar file path, which are used to create and configure tenant-specific sub-containers at runtime.

[0051] Step S3: Package the personalized logic of each tenant into an independent jar file for updating and deployment independently of the common logic.

[0052] In one embodiment, when a tenant accesses the application for the first time, or when the tenant's jar file is updated, the Spring parent container dynamically creates a new child container based on the tenant information. Each child container inherits the common bean definition of the parent container, but can also have its own specific bean configuration.

[0053] Step S4: Allocate an independent class loader (ClassLoader) to each tenant. The class loader is used to load tenant-specific jar files to ensure class isolation between tenants and avoid class conflicts.

[0054] Step S5: Create a Spring subcontainer for each tenant and use the corresponding class loader to load and initialize tenant-specific beans. In this way, each tenant has its own bean instance and configuration.

[0055] In one embodiment, the specific Bean is a tenant-customized service, controller, data access object, etc.

[0056] Step S6: Customize the TenantScope annotation to identify beans whose instances need to be distinguished according to tenants. The TenantScope annotation can extend the Scope function of Spring so that when obtaining these beans, the correct instances can be returned according to the information of the current tenant.

[0057] Among them, TenantScope is a predefined scope for multi-tenant applications in the Spring framework. Developers manage the life cycle of objects in the application on a tenant basis to ensure that the object instances of each tenant are isolated from each other.

[0058] In one embodiment, when processing a business request, the request is intercepted through AOP (Aspect Oriented Programming) or other mechanisms, and the Bean request annotated with TenantScope is routed to the corresponding tenant sub-container according to the tenant information.

[0059] In one embodiment, when a tenant's personalized jar is updated, the Spring parent container can dynamically create a new child container and use a new class loader to load the updated jar file. This process can be performed without interrupting other tenant services.

[0060] In this embodiment, for a Bean annotated with TenantScope, each time the Bean is obtained, the tenant-specific Bean is obtained from the tenant subcontainer according to the tenant ID.

[0061] In a preferred embodiment, when the new sub-container is created and initialized, the service request can be routed to the new sub-container. At the same time, the old sub-container can be safely closed to release related resources. This process needs to ensure a smooth transition to avoid affecting the requests being processed.

[0062] Next, through Figure 2 The core technical points of a technical solution of the method provided by the present invention are explained. Figure 2 The figure shows the detailed execution process of tenant's personalized jar upgrade and update in the Class method based on Spring parent-child container hot loading of multi-tenants provided by the present invention.

[0063] Step S201: create a child container t1 for tenant 1, create a classLoader for tenant 1, load the personalized jar of tenant 1 into the child container, and register the child container of tenant 1 into the parent container.

[0064] Step S202: create a new child container t1_new for tenant 1, create a new classLoader for tenant 1, load the new personalized jar of tenant 1 into the new child container, and register the child container of the new tenant 1 into the parent container.

[0065] Step S203: after receiving the service request of tenant 1, determine whether the request has been executed in the old subcontainer of tenant 1;

[0066] If it has been executed, the old container will be executed times +1, and the bean in the old container will be selected to process the business;

[0067] If it has not been executed, check whether there is a new child container for tenant 1; if it exists and is not in the pending deletion state, close the old container, replace the new container with the old container, and then delete the old container in the container map; if it does not exist or is in the pending deletion state, the old container is executed times +1, and the bean in the old container is selected to process the business.

[0068] Step S204: Before returning the execution result, the execution record of tenant 1 is cleared, and the current execution count of the old container is -1.

[0069] In the scheme of this embodiment, the tenant information is stored by setting the configuration source for the application, and the tenant-specific sub-container is created and configured when the application is running; the personalized logic of each tenant is packaged into an independent jar file, which is updated and deployed independently of the general logic; an independent class loader is assigned to each tenant to load each tenant-specific jar file; a Spring sub-container is created for each tenant, and the corresponding class loader is used to load and initialize each tenant-specific Bean; the TenantScope annotation is customized to identify the Bean whose instance needs to be distinguished according to the tenant; when processing a business request, the annotated Bean is automatically routed to the tenant's Spring sub-container to obtain the Bean; when the tenant's personalized jar is upgraded, the Spring parent container creates a new Spring sub-container for the tenant, loads the Class in the new jar, and closes the old sub-container, while releasing related resources. The technical solution in this embodiment is used to dynamically update the application logic without restarting the server, improve the update and launch speed of the application, and save R&D and operation and maintenance time.

[0070] In one embodiment, a Class device for hot loading multi-tenants based on Spring parent-child containers is provided. Figure 3 The figure shows a structural block diagram of a Class device for hot loading multi-tenants based on Spring parent-child containers provided in this embodiment, wherein the device includes: an initialization unit 10, a first configuration unit 20, a second configuration unit 30, a third configuration unit 40, a fourth configuration unit 50, and a custom unit 60.

[0071] Initialization unit 10: used to initialize the Spring parent container and load the common logic class of the application.

[0072] The first configuration unit 20 is used to set a configuration source for the application to store tenant information, where the information is used to create and configure a tenant-specific sub-container when the application is running.

[0073] The second configuration unit 30 is used to package the personalized logic of each tenant into an independent jar file, and the independent jar file is updated and deployed independently of the general logic.

[0074] The third configuration unit 40 is used to allocate an independent class loader to each tenant, and the class loader is used to load the jar file specific to each tenant.

[0075] The fourth configuration unit 50 is used to create a Spring subcontainer for each tenant, and load and initialize the specific Bean of each tenant through the corresponding class loader.

[0076] Customization unit 60: used to customize the TenantScope annotation, where the TenantScope annotation is used to identify the Bean whose instance needs to be distinguished according to the tenant.

[0077] In a preferred embodiment, when the tenant accesses the application for the first time, or when the tenant's jar file is updated, the Spring parent container dynamically creates a new child container based on the tenant information. Each new child container will inherit the common bean definition of the parent container and also have its own specific bean configuration.

[0078] In a preferred embodiment, the TenantScope annotation is used to identify the beans whose instances need to be distinguished according to the tenant, and further includes: the TenantScope annotation is used to extend the Scope function of Spring, and when these beans are obtained, the correct instance is returned according to the information of the current tenant; for beans with TenantScope annotation, when obtaining the beans, the tenant-personalized beans are obtained from the tenant subcontainer according to the tenant number.

[0079] In a preferred embodiment, when the tenant's personalized jar is updated, the Spring parent container dynamically creates a new child container and loads the updated jar file by using a new class loader. The process is performed without interrupting other tenant services.

[0080] In the scheme of this embodiment, the tenant information is stored by setting the configuration source for the application, and the tenant-specific sub-container is created and configured when the application is running; the personalized logic of each tenant is packaged into an independent jar file, which is updated and deployed independently of the general logic; an independent class loader is assigned to each tenant to load each tenant-specific jar file; a Spring sub-container is created for each tenant, and the corresponding class loader is used to load and initialize each tenant-specific Bean; the TenantScope annotation is customized to identify the Bean whose instance needs to be distinguished according to the tenant; when processing a business request, the annotated Bean is automatically routed to the tenant's Spring sub-container to obtain the Bean; when the tenant's personalized jar is upgraded, the Spring parent container creates a new Spring sub-container for the tenant, loads the Class in the new jar, and closes the old sub-container, while releasing related resources. The technical solution in this embodiment is used to dynamically update the application logic without restarting the server, improve the update and launch speed of the application, and save R&D and operation and maintenance time.

[0081] The Class device based on Spring parent-child container hot loading for multiple tenants in this embodiment is used to implement the aforementioned Class method based on Spring parent-child container hot loading for multiple tenants. Therefore, the specific implementation method of the Class device based on Spring parent-child container hot loading for multiple tenants can be seen in the specific implementation method of the Class method based on Spring parent-child container hot loading for multiple tenants in the previous text. For example, the initialization unit 10 is used to implement step S1 in the above-mentioned Class method based on Spring parent-child container hot loading for multiple tenants, and the first configuration unit 20 is used to implement step S2 in the above-mentioned Class method based on Spring parent-child container hot loading for multiple tenants, etc. Therefore, its specific implementation method can refer to the description of the corresponding various parts of the embodiments. The device provided by the present invention is attached to the method provided by the present invention, and its specific effects can refer to the above-mentioned method, which will not be repeated here.

[0082] In one embodiment, a computing device is provided, comprising:

[0083] A memory for storing program instructions;

[0084] The processor is used to implement the steps of the method for hot-loading multi-tenant Class based on Spring parent-child container as described in any one of the above when executing the computer program. The method for hot-loading multi-tenant Class based on Spring parent-child container of the present invention has obvious advantages and beneficial effects compared with the prior art. It stores tenant information by setting a configuration source for the application, and creates and configures tenant-specific sub-containers when the application is running; the personalized logic of each tenant is packaged into an independent jar file, which is updated and deployed independently of the general logic; an independent class loader is allocated to each tenant to load each tenant-specific jar file; a Spring sub-container is created for each tenant, and the corresponding class loader is used to load and initialize each tenant-specific Bean; the TenantScope annotation is customized to identify the Bean whose instance needs to be distinguished according to the tenant; when processing a business request, the annotated Bean is automatically routed to the tenant's Spring sub-container to obtain the Bean; when the tenant's personalized jar is upgraded, the Spring parent container creates a new Spring sub-container for the tenant, loads the Class in the new jar, and closes the old sub-container, while releasing related resources. The technical solution in this embodiment can realize dynamic updating of application logic without restarting the server, thereby improving the update and launch speed of the application and saving R&D and operation and maintenance time.

[0085] In one embodiment, a computer-readable storage medium is provided, including computer-readable instructions. When a computer reads and executes the computer-readable instructions, the steps of the above-mentioned method of hot-loading a multi-tenant Class based on a Spring parent-child container are implemented. The method of hot-loading a multi-tenant Class based on a Spring parent-child container of the present invention has obvious advantages and beneficial effects compared with the prior art. The configuration source is set for the application to store tenant information, and a tenant-specific sub-container is created and configured when the application is running; the personalized logic of each tenant is packaged into an independent jar file, which is updated and deployed independently of the general logic; an independent class loader is allocated to each tenant to load each tenant-specific jar file; a Spring sub-container is created for each tenant, and the corresponding class loader is used to load and initialize each tenant-specific Bean; a custom TenantScope annotation is used to identify the Bean whose instance needs to be distinguished according to the tenant; when processing a business request, the annotated Bean is automatically routed to the tenant's Spring sub-container to obtain the Bean; when the tenant's personalized jar is upgraded, the Spring parent container creates a new Spring sub-container for the tenant, loads the Class in the new jar, and closes the old sub-container, while releasing related resources. The technical solution in this embodiment can realize dynamic updating of application logic without restarting the server, thereby improving the update and launch speed of the application and saving R&D and operation and maintenance time.

[0086] Through the description of the above implementation methods, technical personnel in the relevant field can understand that for the convenience and simplicity of description, only the division of the above-mentioned functional modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the specific device can be divided into different functional modules to complete all or part of the functions described above.

[0087] Those of ordinary skill in the art will appreciate that the modules and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in terms of function in the above description. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0088] In several embodiments covered by the present application, it should be understood that the disclosed devices, equipment and methods can be implemented in other ways. For example, the division of modules is only a logical function division, and there may be other division methods in actual implementation, such as multiple modules or components can be combined or integrated into another device, or some features can be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or modules, or it can be an electrical, mechanical or other form of connection.

[0089] The modules described as separate components may or may not be physically separated, and the components displayed as modules may or may not be physical modules, that is, they may be located in one place or distributed on multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the embodiments of the present application.

[0090] In addition, each functional module in each embodiment of the present application can be implemented in the form of hardware or in the form of software functional modules. If these functional modules are implemented in the form of software functional modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the present application is essentially or part of the prior art that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a computer program product, which includes one or more computer instructions. When loading and executing computer program instructions on a computer, the process or function according to the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer program product is stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, a computer instruction can be transmitted from a website site, a computer, a server or a data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, server or data center. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or a data center that includes one or more available media integrations. The available media may be magnetic media (eg, floppy disks, hard disks, magnetic tapes), optical media (eg, DVDs), or semiconductor media (eg, solid state disks (SSDs)).

[0091] The above contents are merely examples and explanations of the structure of the present invention. The technicians in this technical field may make various modifications or additions to the specific embodiments described or replace them in a similar manner. As long as they do not deviate from the structure of the invention or exceed the scope defined by the claims, they should all fall within the protection scope of the present invention.

Claims

1. A Class method based on Spring parent-child container hot loading multi-tenant, It is characterized in that include: Initialize the Spring parent container and load the common logic class of the application; Setting a configuration source for the application to store tenant information, the information being used to create and configure a tenant-specific sub-container when the application is running; Package the personalized logic of each tenant into an independent jar file, which is updated and deployed independently of the common logic; Allocate an independent class loader for each tenant, and the class loader is used to load the jar file specific to each tenant; Create a Spring subcontainer for each tenant, and load and initialize the specific beans of each tenant through the corresponding class loader; Customize TenantScope annotation, which is used to identify beans whose instances need to be distinguished according to the tenant; When processing business requests, intercept the requests through aspect-oriented programming or other mechanisms, and route the Bean requests annotated with TenantScope to the corresponding tenant subcontainer according to the tenant information; When the new sub-container is created and initialized, the service request is routed to the new sub-container, and the old sub-container is closed, and related resources are released.

2. The method according to claim 1, It is characterized in that When the tenant accesses the application for the first time, or when the tenant's jar file is updated, the Spring parent container dynamically creates a new child container based on the tenant information. Each new child container will inherit the common bean definition of the parent container and also have its own specific bean configuration.

3. The method according to claim 1, It is characterized in that The TenantScope annotation is used to identify the beans whose instances need to be distinguished according to the tenant, and also includes: the TenantScope annotation is used to extend the Scope function of Spring, and when these beans are obtained, the correct instance is returned according to the information of the current tenant; for beans with TenantScope annotations, when obtaining beans, the tenant-personalized beans are obtained from the tenant subcontainer according to the tenant number.

4. The method according to claim 1, It is characterized in that When the tenant's personalized jar is updated, the Spring parent container dynamically creates a new child container and loads the updated jar file by using a new class loader. This process is performed without interrupting other tenant services.

5. A Class device based on Spring parent-child container hot loading multi-tenant, It is characterized in that include: Initialization unit, first configuration unit, second configuration unit, third configuration unit, fourth configuration unit, custom unit; Initialization unit: used to initialize the Spring parent container and load the common logic class of the application; A first configuration unit: used to set a configuration source for the application to store tenant information, where the information is used to create and configure a tenant-specific sub-container when the application is running; The second configuration unit is used to package the personalized logic of each tenant into an independent jar file, and the independent jar file is updated and deployed independently of the general logic; The third configuration unit is used to allocate an independent class loader to each tenant, and the class loader is used to load the jar file specific to each tenant; The fourth configuration unit is used to create a Spring subcontainer for each tenant, and load and initialize the specific Bean of each tenant through the corresponding class loader; Custom unit: used to customize the TenantScope annotation, which is used to identify the beans whose instances need to be distinguished according to the tenant; When processing business requests, intercept the requests through aspect-oriented programming or other mechanisms, and route the Bean requests annotated with TenantScope to the corresponding tenant subcontainer according to the tenant information; When the new sub-container is created and initialized, the service request is routed to the new sub-container, and the old sub-container is closed, and related resources are released.

6. The device according to claim 5, It is characterized in that When the tenant accesses the application for the first time, or when the tenant's jar file is updated, the Spring parent container dynamically creates a new child container based on the tenant information. Each new child container will inherit the common bean definition of the parent container and also have its own specific bean configuration.

7. The device according to claim 5, It is characterized in that The TenantScope annotation is used to identify the beans whose instances need to be distinguished according to the tenant, and also includes: the TenantScope annotation is used to extend the Scope function of Spring, and when these beans are obtained, the correct instance is returned according to the information of the current tenant; for beans with TenantScope annotations, when obtaining beans, the tenant-personalized beans are obtained from the tenant subcontainer according to the tenant number.

8. The device according to claim 5, It is characterized in that When the tenant's personalized jar is updated, the Spring parent container dynamically creates a new child container and loads the updated jar file by using a new class loader. This process is performed without interrupting other tenant services.

9. A computing device, It is characterized in that include: A memory for storing program instructions; A processor is used to call the program instructions stored in the memory, and execute the method according to any one of claims 1 to 4 according to the obtained program instructions.

10. A computer-readable storage medium, It is characterized in that It includes computer-readable instructions. When a computer reads and executes the computer-readable instructions, it implements the method as claimed in any one of claims 1 to 4. There can be multiple readable media, and the multiple readable media can operate independently of each other.

Citation Information

Cited By

  • Real-time studying and judging method and system based on hot-loadable standard specification package

    CN121935808A

  • A real-time research and judgment method and system based on a heat-loadable standard specification package

    CN121935808B

  • Spring application lazy loading method based on container life cycle control

    CN122653712A