A project hot deployment method and device

By creating custom class loaders and sub-containers for Java projects, the problems of manual deployment and high memory consumption in Java project deployment are solved, enabling automatic and dynamic project deployment and reducing costs and complexity.

CN113849189BActive Publication Date: 2025-01-24SHANGHAI FUDAN KINGSTAR COMPUTER CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111141795.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-09-28
Publication Date
2025-01-24
Estimated Expiration
2041-09-28

AI Technical Summary

Technical Problem

In existing technologies, deploying Java projects requires manual operation, which is inefficient and consumes a lot of memory, resulting in high deployment costs and complexity.

Method used

By creating custom class loaders and sub-containers, different custom class loaders and sub-containers can be created for different projects to load business-related code, avoiding mutual interference between projects and achieving automatic and dynamic deployment.

Benefits of technology

With low memory consumption, the project was deployed automatically and dynamically, reducing deployment costs and complexity, and minimizing the mutual impact between projects.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113849189B_ABST
    Figure CN113849189B_ABST
Patent Text Reader

Abstract

The present application discloses a project hot deployment method and device. When performing project deployment, the method and device respectively create different custom class loaders and different sub-containers for different projects to be deployed, and use different custom class loaders to load project file packages of different projects to be deployed, and use different sub-containers to load resources (such as components) in file packages of different projects to be deployed, so that project instances of different projects to be deployed are isolated from each other, and the mutual influence between different projects is reduced. Moreover, by only loading business-related codes (project file packages and data access layer components only involve business-related codes), the project is automatically and dynamically deployed with less memory consumption, thereby reducing the cost and complexity of deploying the project.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of project development and deployment, and in particular to a project hot deployment method and device. Background Art

[0002] The automated development platform can generate Java code based on the interface operation method. Generally, Java projects need to be compiled and packaged to generate jar files or war files. They must be manually deployed through the web container before they can provide interface services to the outside world.

[0003] The new automation platform will generate a large amount of Java project code. Deploying these codes to the server requires a lot of work. Correspondingly, dedicated personnel are required to manually deploy the generated code, maintain and solve a series of problems that occur during deployment. This is inefficient and requires a large amount of manual work. Therefore, there is an urgent need for an automatic and dynamic project deployment solution that can replace manual operations. Summary of the invention

[0004] In view of this, the present application provides a project hot deployment method and device for automatically and dynamically deploying projects without manual operation and with less memory consumption, so as to reduce the cost and complexity of deploying projects.

[0005] The specific technical solutions are as follows:

[0006] A project hot deployment method, comprising:

[0007] Load the project file package of the target project to be deployed through the created custom class loader;

[0008] The resources contained in the project file package are loaded through the created sub-container; wherein the sub-container inherits the resources in the parent container of the host project of the target project and can share common resources, and different projects to be deployed correspond to different custom class loaders and different sub-containers respectively;

[0009] Loading data access layer components into the host project;

[0010] The interface address mapping of the service interface of the predetermined page service is registered in the parent container of the host project, so as to load the target project into the host project and provide the predetermined page service.

[0011] Optionally, the loading of the project file package of the target project to be deployed by the created custom class loader includes:

[0012] For a target project to be deployed, create a custom class loader for the target project;

[0013] The created custom class loader is used to load the jar file package or war file package of the target project.

[0014] Optionally, loading the resources contained in the project file package by using the created sub-container includes:

[0015] Use a scanner to scan components in the project file package, and register the scanned components in the parent container of the host project;

[0016] A subcontainer is created, and the components contained in the project file package are loaded by using the created subcontainer.

[0017] Optionally, loading the data access layer component into the host project includes:

[0018] Scanning the data access layer component using a scanner, registering the scanned data access layer component to the parent container of the host project; and clearing the cached historical registration information of the data access layer component before registration;

[0019] Load the data access layer components.

[0020] Optionally, the registering the interface address mapping of the service interface of the predetermined page service into the parent container of the host project so as to load the target project into the host project and provide the predetermined page service includes:

[0021] Registering the uniform resource locator (URL) mapping of the hypertext transfer protocol (http) interface into the parent container of the host project, so as to load the target project into the host project and provide http service;

[0022] Wherein, the cached historical registration information of the URL mapping is cleared before registration.

[0023] Optionally, the above method further includes:

[0024] When the target project needs to be uninstalled, the target project and the resources occupied by the target project are uninstalled by deleting the class loader and the subcontainer corresponding to the target project.

[0025] A project hot deployment device, comprising:

[0026] A first loading processing module, used for loading a project file package of a target project to be deployed through a created custom class loader;

[0027] A second loading processing module is used to load the resources contained in the project file package through the created sub-container; wherein the sub-container inherits the resources in the parent container of the host project of the target project and can share common resources, and different to-be-deployed projects correspond to different custom class loaders and different sub-containers respectively;

[0028] A third loading processing module, used for loading the data access layer component into the host project;

[0029] The interface address mapping registration module is used to register the interface address mapping of the service interface of the predetermined page service into the parent container of the host project, so as to load the target project into the host project and provide the predetermined page service.

[0030] Optionally, the first loading processing module is specifically configured to:

[0031] For a target project to be deployed, create a custom class loader for the target project;

[0032] Use the created custom class loader to load the jar file package or war file package of the target project;

[0033] The second loading processing module is specifically used to:

[0034] Use a scanner to scan components in the project file package, and register the scanned components in the parent container of the host project;

[0035] A subcontainer is created, and the components contained in the project file package are loaded by using the created subcontainer.

[0036] Optionally, the third loading processing module is specifically used to:

[0037] Scanning the data access layer component using a scanner, registering the scanned data access layer component to the parent container of the host project; and clearing the cached historical registration information of the data access layer component before registration;

[0038] Load data access layer components;

[0039] The interface address mapping registration module is specifically used for:

[0040] Register the url mapping of the http interface to the parent container of the host project, so as to load the target project into the host project and provide http service;

[0041] Wherein, the cached historical registration information of the URL mapping is cleared before registration.

[0042] Optionally, the above device further includes:

[0043] The uninstall processing module is used to uninstall the target project and the resources occupied by the target project by deleting the class loader and subcontainer corresponding to the target project when the target project needs to be uninstalled.

[0044] According to the above scheme, the project hot deployment method and device provided by the present application, when performing project deployment, creates different custom class loaders and different sub-containers for different projects to be deployed, and uses different custom class loaders to load project file packages of different projects to be deployed, and uses different sub-containers to load resources (such as components) in file packages of different projects to be deployed, so that project instances of different projects to be deployed are isolated from each other, reducing the mutual influence between different projects, and by only loading business-related code (project file packages and data access layer components only involve business-related code), it is achieved that the project is automatically and dynamically deployed with less memory consumption, thereby reducing the cost and complexity of deploying the project. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] In order to more clearly illustrate the embodiments of the present application 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 embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.

[0046] Figure 1 It is a flow chart of the project hot deployment method provided by this application;

[0047] Figure 2 This is a schematic diagram of registering data access and URL mapping to the parent container of the host project provided by this application;

[0048] Figure 3 This is an application example of the project hot deployment method provided by this application;

[0049] Figure 4 It is another flow chart of the project hot deployment method provided by this application;

[0050] Figure 5 It is a structural schematic diagram of the project hot deployment device provided in this application. DETAILED DESCRIPTION

[0051] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0052] Generally, the deployment and release of a project requires manual compilation and packaging, and scripts or operating system commands are needed to start the deployment of the web application project, which is deployed through a web container to provide external interface services. In order to achieve an automated deployment solution that replaces manual operations, there is currently a technology based on osgi (Open Service Gateway Initiative) that can perform automated hot deployment of projects, but this technology requires hot loading of components containing web containers, resulting in relatively high server memory consumption.

[0053] In order to solve this problem, the present application discloses a project hot deployment method and device to achieve automatic and dynamic deployment and release of projects without manual operation and with less memory consumption, and provide predetermined page services (such as http services), thereby reducing the cost and complexity of deploying projects.

[0054] The processing flow of the project hot deployment method disclosed in this application is as follows Figure 1 As shown, specifically including:

[0055] Step 101: Load the project file package of the target project to be deployed through the created custom class loader.

[0056] The project file package may be, but is not limited to, a jar file package or a war file package obtained by compiling and packaging the project code (eg, java code).

[0057] For the target project to be deployed, the embodiment of the present application creates a custom class loader for it, and uses the custom class loader to load the project file package of the target project to be deployed, such as a jar file package.

[0058] The created custom class loader inherits the application class loader of the host project (or host application).

[0059] For different projects to be deployed, create different custom class loaders for them, and use different custom class loaders to load the project file packages of different projects to be deployed. By using different custom class loaders, different projects are isolated from each other. In addition, since each custom class loader inherits the application class loader of the host project, there is no need to repeatedly load common resources.

[0060] Step 102: Load the resources contained in the project file package through the created sub-container.

[0061] On the basis of loading the project file package of the target project to be deployed through a custom class loader, the scanner is used to scan the components in the project file package of the target project, the scanned components are registered in the parent container of the host project, and a child container is created for the target project to be deployed. The created child container is used to load these resources, that is, load the various components in the project file package of the target project.

[0062] The scanner is specifically the scanning component in the parent container of the host project.

[0063] The child container inherits the resources in the parent container of the host project and can share common resources, which may include but are not limited to common data source information. Different projects to be deployed correspond to different custom class loaders and different child containers.

[0064] For example, see Figure 2 After using the custom class loader to load the jar package of the project to be deployed, use the scanner in the parent container of the host project to scan the components in the jar package, register the scanned components with the parent container of the host project, and create a spring subcontainer to load these resources (components in the jar package). For different projects to be deployed, different spring subcontainers are used to isolate the instances of different projects to be deployed from each other to avoid mutual influence between different projects.

[0065] Step 103: Load the data access layer component into the host project.

[0066] For the above-mentioned dynamically loaded target project to be deployed, the data access layer component has not been loaded by the system, so it is also necessary to scan the data access layer component and load it.

[0067] Specifically, a scanner (a scanning component in the parent container of the host project) may be used to scan the data access layer component, the scanned data access layer component may be registered in the parent container of the host project, and the data access layer component may be loaded.

[0068] Among them, before registration, the cached historical registration information of the data access layer component is cleared.

[0069] Exemplarily, the data access layer components may include mybatisPlus components. Before scanning the data access layer components and registering them in the parent container of the host project, the previously cached registration information of these components is first deleted.

[0070] Step 104: Register the interface address mapping of the service interface of the predetermined page service into the parent container of the host project, so as to load the target project into the host project and provide the predetermined page service.

[0071] The interface address mapping of the service interface of the reservation page service is also not registered in the system. Therefore, it is necessary to register and update the interface address mapping of the service interface of the reservation page service to the system, and clear the cached historical registration information of the interface address mapping before registration and updating.

[0072] The scheduled page service may be, but is not limited to, an http (HyperText Transfer Protocol) service. Taking the http service as an example, the url mapping of the http interface may be registered in the parent container of the host project (and the previously cached url mapping registration information may be cleared before registration), so as to load the target project to be deployed into the host project and provide the http service, thereby realizing automatic and dynamic hot deployment of the target project to be deployed.

[0073] Since the project file package and data access layer components only involve business-related codes, during the hot deployment of the project, this application can complete the automatic and dynamic deployment of the project by creating corresponding custom class loaders and spring subcontainers to only load business-related codes on the basis of relevant loaders (such as application class loaders) and resource inheritance. It does not deploy through the web container, and accordingly there is no need to hot load the components containing the web container, thereby reducing memory occupancy.

[0074] Based on the project hot deployment method disclosed in the embodiment of this application, see Figure 3 In the examples provided, in actual applications, the project release directory can be scanned regularly. When a project to be deployed is scanned, the jar file package of the project is loaded by using a custom class loader, the components in the jar file package are loaded by using the created spring subcontainer, and a series of processes such as registering data access layer components and url mapping are performed to achieve automatic and dynamic deployment of the project.

[0075] According to the above scheme, it can be known that the method of the embodiment of the present application, when performing project deployment, creates different custom class loaders and different sub-containers for different projects to be deployed, and uses different custom class loaders to load project file packages of different projects to be deployed, and uses different sub-containers to load resources (such as components) in file packages of different projects to be deployed, so that project instances of different projects to be deployed are isolated from each other, reducing the mutual influence between different projects, and by only loading business-related code (project file packages and data access layer components only involve business-related code), it is achieved that the project is automatically and dynamically deployed with less memory consumption, thereby reducing the cost and complexity of deploying the project.

[0076] In one embodiment, see Figure 4 The processing flow of the project hot deployment method provided, the method of this application may also include:

[0077] Step 105: When the target project needs to be uninstalled, the target project and the resources occupied by the target project are uninstalled by deleting the class loader and subcontainer corresponding to the target project.

[0078] Specifically, when you need to uninstall a deployed project, you can directly delete the class loader and subcontainer corresponding to the project, such as the spring subcontainer, to uninstall the project and its occupied resources, such as memory resources. Since the instances of different deployed projects are isolated from each other, uninstalling one project will not affect other projects.

[0079] Corresponding to the above method, the present application embodiment also discloses a memory management device, such as Figure 5 As shown, the device comprises:

[0080] The first loading processing module 501 is used to load the project file package of the target project to be deployed through the created custom class loader;

[0081] The second loading processing module 502 is used to load the resources contained in the project file package through the created sub-container; wherein the sub-container inherits the resources in the parent container of the host project of the target project and can share common resources, and different to-be-deployed projects correspond to different custom class loaders and different sub-containers respectively;

[0082] The third loading processing module 503 is used to load the data access layer component into the host project;

[0083] The interface address mapping registration module 504 is used to register the interface address mapping of the service interface of the predetermined page service into the parent container of the host project, so as to load the target project into the host project and provide the predetermined page service.

[0084] In one embodiment, the first loading processing module 501 is specifically configured to:

[0085] For a target project to be deployed, create a custom class loader for the target project;

[0086] Use the created class loader to load the jar file package or war file package of the target project;

[0087] The second loading processing module 502 is specifically used for:

[0088] Use a scanner to scan the components in the project file package, and register the scanned components into the parent container of the host project;

[0089] A subcontainer is created, and the components contained in the project file package are loaded by using the created subcontainer.

[0090] In one embodiment, the third loading processing module 503 is specifically configured to:

[0091] Use the scanner to scan the data access layer components, and register the scanned data access layer components to the parent container of the host project; clear the cached historical registration information of the data access layer components before registration;

[0092] Load data access layer components;

[0093] The interface address mapping registration module 504 is specifically used for:

[0094] Register the uniform resource locator (URL) mapping of the hypertext transfer protocol (http) interface to the parent container of the host project, so as to load the target project into the host project and provide http service;

[0095] Wherein, the cached historical registration information of the URL mapping is cleared before registration.

[0096] In one embodiment, the above device further includes:

[0097] The uninstall processing module is used to uninstall the target project and the resources occupied by the target project by deleting the class loader and subcontainer corresponding to the target project when the target project needs to be uninstalled.

[0098] As for the project hot deployment device disclosed in the embodiment of the present application, since it corresponds to the project hot deployment method disclosed in the above method embodiments, the description is relatively simple. For the relevant similarities, please refer to the description of the corresponding method embodiments above, which will not be described in detail here.

[0099] In summary, the project hot deployment method and device disclosed in the present application manage and isolate the deployed projects by creating different custom class loaders and sub-containers for different projects to be deployed, and integrate the created sub-containers with the container of the host project (i.e., the parent container) by inheriting the class loader and resources of the host project, and through dynamic scanning and loading of data access layer components, registration and updating of http interface url mapping, the system does not require manual operation, and can automatically and dynamically deploy and publish projects with less memory consumption, and provide http services, thereby reducing the cost and complexity of deploying projects.

[0100] It should be noted that the various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.

[0101] For the convenience of description, the above system or device is described by dividing it into various modules or units according to its functions. Of course, when implementing the present application, the functions of each unit can be implemented in the same or multiple software and / or hardware.

[0102] It can be known from the description of the above implementation methods that those skilled in the art can clearly understand that the present application can be implemented by means of software plus a necessary general hardware platform. Based on such an understanding, the technical solution of the present application can be essentially or partly contributed to the prior art in the form of a software product, which can be stored in a storage medium such as ROM / RAM, a magnetic disk, an optical disk, etc., and includes several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in the various embodiments of the present application or certain parts of the embodiments.

[0103] Finally, it should be noted that, in this article, relational terms such as first, second, third and fourth are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the statement "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.

[0104] The above is only a preferred implementation of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.

Claims

1. A project hot deployment method, characterized in that: include: Load the project file package of the target project to be deployed through the created custom class loader; The resources contained in the project file package are loaded through the created sub-container; wherein the sub-container inherits the resources in the parent container of the host project of the target project and can share common resources, and different projects to be deployed correspond to different custom class loaders and different sub-containers respectively; Loading data access layer components into the host project; Registering the interface address mapping of the service interface of the predetermined page service into the parent container of the host project, so as to load the target project into the host project and provide the predetermined page service; The project file package of the target project to be deployed is loaded by the created custom class loader, including: For a target project to be deployed, create a custom class loader for the target project; Use the created custom class loader to load the jar file package or war file package of the target project; The created custom class loader inherits the application class loader of the host project; The loading of resources contained in the project file package through the created sub-container includes: Use a scanner to scan components in the project file package, and register the scanned components in the parent container of the host project; Creating a subcontainer, and using the created subcontainer to load the components contained in the project file package; The scanner is a scanning component in the parent container of the host project.

2. The method according to claim 1, characterized in that The step of loading the data access layer component into the host project comprises: Scanning the data access layer component using a scanner, registering the scanned data access layer component to the parent container of the host project; and clearing the cached historical registration information of the data access layer component before registration; Load the data access layer components.

3. The method according to claim 1, characterized in that The interface address mapping of the service interface of the predetermined page service is registered in the parent container of the host project, so as to load the target project into the host project and provide the predetermined page service, including: Registering the uniform resource locator (URL) mapping of the hypertext transfer protocol (http) interface into the parent container of the host project, so as to load the target project into the host project and provide http service; Wherein, the cached historical registration information of the URL mapping is cleared before registration.

4. The method according to any one of claims 1 to 3, characterized in that: Also includes: When the target project needs to be uninstalled, the target project and the resources occupied by the target project are uninstalled by deleting the class loader and the subcontainer corresponding to the target project.

5. A project hot deployment device, characterized in that: include: A first loading processing module, used for loading a project file package of a target project to be deployed through a created custom class loader; A second loading processing module is used to load the resources contained in the project file package through the created sub-container; wherein the sub-container inherits the resources in the parent container of the host project of the target project and can share common resources, and different to-be-deployed projects correspond to different custom class loaders and different sub-containers respectively; A third loading processing module, used for loading the data access layer component into the host project; An interface address mapping registration module, used to register the interface address mapping of the service interface of the predetermined page service into the parent container of the host project, so as to load the target project into the host project and provide the predetermined page service; The first loading processing module is specifically used to: For a target project to be deployed, create a custom class loader for the target project; Use the created custom class loader to load the jar file package or war file package of the target project; The created custom class loader inherits the application class loader of the host project; The second loading processing module is specifically used to: Use a scanner to scan components in the project file package, and register the scanned components in the parent container of the host project; Creating a subcontainer, and using the created subcontainer to load the components contained in the project file package; The scanner is a scanning component in the parent container of the host project.

6. The device according to claim 5, characterized in that The third loading processing module is specifically used for: Scanning the data access layer component using a scanner, registering the scanned data access layer component to the parent container of the host project; and clearing the cached historical registration information of the data access layer component before registration; Load data access layer components; The interface address mapping registration module is specifically used for: Register the url mapping of the http interface to the parent container of the host project, so as to load the target project into the host project and provide http service; Wherein, the cached historical registration information of the URL mapping is cleared before registration.

7. The device according to claim 5, characterized in that Also includes: The uninstall processing module is used to uninstall the target project and the resources occupied by the target project by deleting the class loader and subcontainer corresponding to the target project when the target project needs to be uninstalled.

Citation Information

Patent Citations

  • Java web project based hot deploy implementation method

    CN105242948A

  • Hot deployment method and system for Java application

    CN105389186A