Code hot deployment method based on Grouping and configuration center

Through the code hot deployment method based on Groovy and configuration center, the problem of traditional code deployment methods increasing deployment complexity and business interruption risks is solved, and the application is quickly iterated and deployed, improving the flexibility and maintainability of the code.

CN119987845APending Publication Date: 2025-05-13BEIJING BAIJU YIXING TECH CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202510177440.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-18
Publication Date
2025-05-13

AI Technical Summary

Technical Problem

Traditional code deployment methods require downtime, replacement of code packages, and restarting applications, which increases the deployment complexity and risk of business interruption, making it difficult to meet the application's rapid iteration and deployment needs.

Method used

The code hot deployment method based on Groovy and configuration center is adopted. Groovy scripts are loaded through GroovyClassLoader, and reference pointers of new and old classes are saved using symbolic links, container configuration files are monitored, and configuration centralized management and dynamic refresh are realized through the configuration center to achieve rapid hot deployment of code.

Benefits of technology

It realizes rapid iteration and deployment of applications, reduces downtime and business interruption risks, improves code flexibility and maintainability, and increases application availability and user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119987845A_ABST
    Figure CN119987845A_ABST
Patent Text Reader

Abstract

The invention provides a code hot deployment method based on a Grouping and a configuration center, which comprises the following steps of: integrating a Grouping script-using a template design mode, extracting a dynamic code of business logic, and adding the dynamic code to the Grouping; the method comprises the following steps: introducing a GraovyClassLoader, loading the GraovyClassLoader into a JVM (Java Virtual Machine) of JAVA, and calling the GraovyClassLoader; the quoted symbolic link is that in the JVM, the definition name of the newly loaded Class is replaced; according to the method, the changed codes are compiled into the byte codes in real time by utilizing the dynamic compiling characteristic of the Groupy, and the new configuration information and the application codes are pushed to each application node through a real-time pushing mechanism of the configuration center. After the application node receives the new configuration information and code, the application node can dynamically load and replace the original configuration and code, so that the rapid updating and deployment of the application are realized, more complex code change and dynamic loading can be realized, and the flexibility and expandability of the application are further improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to a code hot deployment method, in particular to a code hot deployment method based on Groovy and a configuration center, and belongs to the technical field of software development. Background Art

[0002] Hot Deployment: refers to a technology that allows modifications to some code or resources to take effect immediately without stopping the entire application while the application is running. In the software development process, hot deployment is a very useful tool that can significantly improve the efficiency of developers.

[0003] Configuration Center: It is a basic service component that manages the configuration of various applications in a unified manner. It extracts the configuration from the application and manages it centrally, solving problems such as dynamic configuration changes, permission management, persistence, and operation and maintenance costs. The configuration center allows applications to obtain the required configuration from a centralized location without having to worry about the specific storage location of the configuration or when it changes.

[0004] Groovy: is an agile development language based on JVM (Java Virtual Machine), which can be well integrated with Java code and can also be used to extend existing code.

[0005] With the rapid development of the software industry, iterative updates and rapid deployment of applications have become an important manifestation of corporate competitiveness. Traditional code deployment methods usually require downtime, code package replacement, application restart, etc., which not only increases the complexity of deployment, but also affects business continuity. Therefore, a code hot deployment method based on Groovy and configuration center is proposed. Summary of the invention

[0006] In view of this, the present invention provides a code hot deployment method based on Groovy and a configuration center to solve or alleviate the technical problems existing in the prior art, and at least provide a beneficial choice.

[0007] The technical solution of the embodiment of the present invention is implemented as follows: a code hot deployment method based on Groovy and a configuration center, comprising the following steps:

[0008] S1. Integrate Groovy scripts - use template design patterns to extract dynamic code of business logic and add it to Groovy;

[0009] S2. Introduce GroovyClassLoader, load it into JAVA's JVM, and call it;

[0010] S3, referenced symbolic link - in the JVM, the qualified name of the newly loaded class Class is replaced;

[0011] S4, use symbolic links to save reference pointers of the new and old classes;

[0012] S5. Monitor container configuration files - use the configuration center to implement centralized management and dynamic refresh of configurations;

[0013] S6. Code hot deployment - make configuration changes through the configuration center and send change notifications to the server;

[0014] S7. The server performs a reinitialization operation of the Groovy object. After the initialization is completed, the Groovy object is returned to the server, and a success notification is sent to the configuration center through the server to complete the deployment.

[0015] Further preferably, the extracting of the dynamic code of the business logic is to define a Java template class using a template design pattern, and extract the dynamic code of the business logic through the Java template class;

[0016] The Java template class contains a skeleton for executing business logic and a loadClass method for calling a Groovy script.

[0017] Further preferably, the introduction of GroovyClassLoader is used to load the Groovy script into the JVM of JAVA, and call and execute it to form a new class Class.

[0018] Further preferably, the changing qualified name is used to rename the newly loaded class Class to distinguish between the new and old Class.

[0019] Further preferably, the reference pointers of the old and new Classes are saved in a symbolic link manner, so as to directly replace the references when the Class is rewritten and loaded and the class name changes.

[0020] Further preferably, the monitoring container configuration file comprises the following steps:

[0021] S51. Through the configuration monitoring function of the configuration center, the changes of the groovy script can be perceived in real time;

[0022] S52. Reload the Groovy script source code when the configuration changes;

[0023] S53. Recompile the Groovy script.

[0024] Further preferably, in S51, the configuration monitoring function is implemented by using an event listener for monitoring changes in the groovy script configuration.

[0025] Further preferably, after receiving the success notification, the configuration center generates a modification success feedback through the configuration center.

[0026] Further preferably, the configuration center is Spring Cloud Config or Nacos.

[0027] The embodiment of the present invention has the following advantages due to the adoption of the above technical solution:

[0028] 1. The present invention can achieve rapid iteration and deployment of applications by performing hot code deployment based on Groovy and the configuration center, improve the flexibility and maintainability of the code, reduce the risk of downtime and business interruption, and increase application availability and user experience.

[0029] Second, the present invention utilizes the dynamic compilation characteristics of Groovy to compile the changed code into bytecode in real time, and pushes the new configuration information and application code to each application node through the real-time push mechanism of the configuration center. After receiving the new configuration information and code, the application node will dynamically load and replace the original configuration and code, thereby realizing rapid update and deployment of the application, and can also realize more complex code changes and dynamic loading, further improving the flexibility and scalability of the application.

[0030] The above summary is for illustrative purposes only and is not limiting in any way. In addition to the illustrative aspects, embodiments and features described above, further aspects, embodiments and features of the present invention will be readily apparent by reference to the accompanying drawings and the following detailed description. BRIEF DESCRIPTION OF THE DRAWINGS

[0031] 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 some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0032] Figure 1 Integrate the Groovy script logic diagram for the present invention;

[0033] Figure 2 A logical diagram of the symbolic links referenced by the present invention;

[0034] Figure 3 The figure is a flow chart of the code hot deployment method of the present invention. DETAILED DESCRIPTION

[0035] In the following, only some exemplary embodiments are briefly described. As those skilled in the art will appreciate, the described embodiments may be modified in various ways without departing from the spirit or scope of the present invention. Therefore, the drawings and descriptions are considered to be exemplary and non-restrictive in nature.

[0036] It should be noted that the terms "first", "second", "symmetrical", "array", etc. are only used to distinguish between description and position description purposes, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Therefore, the definition of "first", "symmetrical", etc. can explicitly or implicitly include one or more of these features; similarly, when the number of certain features is not limited in the form of words such as "two" or "three", it should be noted that this feature also explicitly or implicitly includes one or more feature quantities.

[0037] As an agile development language based on JVM, Groovy's dynamic compilation and flexible expansion features make hot code deployment possible. At the same time, the configuration center, as an infrastructure for centralized management of application configuration, can realize dynamic configuration changes and real-time push. Combining Groovy with the configuration center can realize fast hot code deployment without stopping or restarting the application, thereby improving application availability and user experience.

[0038] Hot deployment is to add or replace class files in the JVM in real time while the program is running without restarting the JVM. This ensures that the hot deployment process has little impact on application performance and can maintain application stability when errors occur.

[0039] JVM uses ClassLoader to load class files. The built-in parent delegation model avoids the failure of core class library loading due to class conflicts by specifying the order in which class files are loaded. A single ClassLoader cannot load classes with the same fully qualified name; it cannot modify the declaration of a loaded class; it cannot unload a loaded class unless the entire ClassLoader is removed.

[0040] GroovyClassLoader is a class loader provided by Groovy that allows you to dynamically load and compile Groovy code. In Java applications, you can use GroovyClassLoader to load and execute Groovy scripts at runtime without restarting the JVM.

[0041] JVM (Java Virtual Machine) is a bytecode runtime environment for executing Java applications. It is the core component of the Java platform and is responsible for converting Java bytecode into machine code and executing it on the underlying operating system. JVM provides an abstraction layer that enables Java programs to run on different platforms without modifying the source code.

[0042] The embodiments of the present invention are described in detail below with reference to the accompanying drawings.

[0043] Embodiment 1

[0044] like Figure 1-Figure 3 As shown, an embodiment of the present invention provides a code hot deployment method based on Groovy and a configuration center, comprising the following steps:

[0045] S1. Integrate Groovy scripts - use template design patterns to extract dynamic code of business logic and add it to Groovy;

[0046] S2. Introduce GroovyClassLoader, load it into JAVA's JVM, and call it;

[0047] S3, referenced symbolic link - in the JVM, the qualified name of the newly loaded class Class is replaced;

[0048] S4, use symbolic links to save reference pointers of the new and old classes;

[0049] S5. Monitor container configuration files - use the configuration center to implement centralized management and dynamic refresh of configurations;

[0050] S6. Code hot deployment - make configuration changes through the configuration center and send change notifications to the server;

[0051] S7. The server performs a reinitialization operation of the Groovy object. After the initialization is completed, the Groovy object is returned to the server, and a success notification is sent to the configuration center through the server to complete the deployment.

[0052] In one embodiment, the dynamic code of the business logic is extracted by defining a Java template class using a template design pattern, and extracting the dynamic code of the business logic through the Java template class;

[0053] The Java template class contains the skeleton for executing business logic and the loadClass method for calling the Groovy script.

[0054] Introduce GroovyClassLoader to load Groovy scripts into JAVA's JVM and call and execute them to form a new class Class;

[0055] By using the template design pattern, the dynamic code of the business logic is extracted. It is implemented in Groovy, and the GroovyClassLoader is introduced to load it into the JVM of JAVA for calling. Figure 1 As shown in the figure, the Main class depends on the methods or properties defined in the Game interface, and the arrow points from the Main class to the Game interface. The GroovyClassLoader class depends on the two implementation classes, GroovyOneImpl and GroovyTwoImpl, and the arrow points from the GroovyClassLoader class to the GroovyOneImpl and GroovyTwoImpl classes. The GroovyOneImpl class provides the implementation of all the methods defined in the Game interface; similar to GroovyOneImpl, the GroovyTwoImpl class also provides the implementation of all the methods defined in the Game interface;

[0056] The specific code example is as follows:

[0057]

[0058]

[0059]

[0060]

[0061] In one embodiment, the qualified name is replaced to rename the newly loaded class Class, distinguish the new and old Classes, and save the reference pointers of the new and old Classes in the form of symbolic links, so as to directly replace the reference when the class name changes when the class is rewritten and loaded;

[0062] Since two classes in JVM cannot be overwritten or renamed, the newly loaded class needs to change the qualified name, such as Test, the new class name is changed to Test_01. At this time, the program cannot access the new Class by the class name because the class name has changed. Therefore, the symbolic link method is used to save the reference pointers of the new and old Classes. Whenever the Class is rewritten and loaded and the class name changes, the reference is directly replaced, as shown in the following example: Figure 2 shown.

[0063] In one embodiment, monitoring the container configuration file includes the following steps:

[0064] S51. Through the configuration monitoring function of the configuration center, the changes of the groovy script can be perceived in real time;

[0065] S52. Reload the Groovy script source code when the configuration changes;

[0066] S53. Recompile the Groovy script.

[0067] In S51, the configuration monitoring function is implemented by using an event listener to monitor changes in the groovy script configuration.

[0068] The configuration center generates modification success feedback through the configuration center after receiving the success notification.

[0069] The configuration center is Spring Cloud Config.

[0070] Spring Cloud Config is a configuration management tool for managing external configuration in distributed systems. It supports server and client modes, which can help developers centrally manage application configurations for all environments and support dynamic updates of configurations. In Spring Cloud, the configuration server stores configuration properties, and client applications can obtain configuration information from the configuration server.

[0071] When using Spring Cloud Config as the configuration center to monitor the container configuration file, first configure the warehouse address in the SpringCloud Config Server to ensure that the configuration file can be accessed, then configure the address of the Server in the Spring CloudConfig Client, and enable the automatic configuration refresh function, which can be achieved through the @RefreshScope annotation so that the Client can dynamically obtain the latest configuration from the Server; then use SpringCloud Bus in combination with Spring Cloud Stream, and configure a listener to broadcast configuration change events. When a configuration change is detected, it triggers the reloading of the configuration. You can also listen to configuration change events through Spring Cloud Stream. When a configuration change event occurs, use Spring's @EventListener annotation to listen to the event and reload the Groovy script in the event handling method. Use Groovy's GroovyShell class to recompile and execute the Groovy script to update the application's state logic. The Client is the application end, and the specific logic is as follows: Figure 3 shown.

[0072] Embodiment 2

[0073] The embodiment of the present invention also provides a code hot deployment method based on Groovy and a configuration center, comprising the following steps:

[0074] S1. Integrate Groovy scripts - use template design patterns to extract dynamic code of business logic and add it to Groovy;

[0075] S2. Introduce GroovyClassLoader, load it into JAVA's JVM, and call it;

[0076] To extract the dynamic code of business logic, a Java template class is defined using the template design pattern, and the dynamic code of business logic is extracted through the Java template class;

[0077] The Java template class contains the skeleton for executing business logic and the loadClass method for calling the Groovy script.

[0078] Introduce GroovyClassLoader to load Groovy scripts into JAVA's JVM and call and execute them to form a new class Class;

[0079] By using the template design pattern, the dynamic code of the business logic is extracted. It is implemented in Groovy, and the GroovyClassLoader is introduced to load it into the JVM of JAVA for calling. Figure 1 As shown in the figure, the Main class depends on the methods or properties defined in the Game interface, and the arrow points from the Main class to the Game interface. The GroovyClassLoader class depends on the two implementation classes, GroovyOneImpl and GroovyTwoImpl, and the arrow points from the GroovyClassLoader class to the GroovyOneImpl and GroovyTwoImpl classes. The GroovyOneImpl class provides the implementation of all methods defined in the Game interface; similar to GroovyOneImpl, the GroovyTwoImpl class also provides the implementation of all methods defined in the Game interface.

[0080] S3, referenced symbolic link - in the JVM, the qualified name of the newly loaded class Class is replaced;

[0081] S4, use symbolic links to save reference pointers of the new and old classes;

[0082] Replace qualified name, which is used to rename the newly loaded class, distinguish the old and new classes, and save the reference pointers of the new and old classes in the form of symbolic links. It is used to directly replace the reference when the class name changes when the class is rewritten and loaded;

[0083] Since two classes in JVM cannot be overwritten or renamed, the newly loaded class needs to change the qualified name, such as Test, the new class name is changed to Test_01. At this time, the program cannot access the new Class by the class name because the class name has changed. Therefore, the symbolic link method is used to save the reference pointers of the new and old Classes. Whenever the Class is rewritten and loaded and the class name changes, the reference is directly replaced, as shown in the following example: Figure 2 shown.

[0084] S5. Monitor container configuration files - use the configuration center to implement centralized management and dynamic refresh of configurations;

[0085] Monitoring container configuration files involves the following steps:

[0086] S51. Through the configuration monitoring function of the configuration center, the changes of the groovy script can be perceived in real time;

[0087] S52. Reload the Groovy script source code when the configuration changes;

[0088] S53. Recompile the Groovy script.

[0089] In S51, the configuration monitoring function is implemented by using an event listener to monitor changes in the groovy script configuration.

[0090] The configuration center generates modification success feedback through the configuration center after receiving the success notification.

[0091] The configuration center is Nacos.

[0092] Nacos is a dynamic service discovery, configuration management, and service management platform that makes it easier to build cloud-native applications. Nacos is open sourced by Alibaba and can almost seamlessly replace Spring Cloud Eureka and Spring CloudConfig.

[0093] When using Nacos as the configuration center to monitor container configuration files, first configure Nacos Server: add configuration information in Nacos Server to support configuration management in different environments, configure data ID and Group so that Client can correctly obtain the configuration; then configure Nacos Client: in Spring Cloud application, add Nacos dependency and configure the address of Nacos Server, use @NacosValue or @NacosConfigurationProperties annotation to inject configuration properties, enable Nacos configuration automatic refresh function, so that Client can dynamically obtain the latest configuration from Nacos; then listen for configuration changes: use Nacos listening function to listen for configuration change events by adding @NacosConfigListener annotation, and trigger configuration reloading when configuration change events occur; finally, hot reload of Groovy script: in Nacos Client application, listen for configuration change events, reload Groovy script when configuration changes are detected, and use Groovy's GroovyShell class to recompile and execute Groovy script, so as to update the application state logic, where Client is the application end.

[0094] S6. Code hot deployment - make configuration changes through the configuration center and send change notifications to the server;

[0095] S7. The server performs a reinitialization operation of the Groovy object. After the initialization is completed, the Groovy object is returned to the server, and a success notification is sent to the configuration center through the server to complete the deployment.

[0096] The above are only specific embodiments of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art can easily think of various changes or substitutions within the technical scope disclosed by the present invention, which should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.

Claims

1. A code hot deployment method based on Groovy and configuration center, characterized in that: The following steps are involved: S1. Integrate Groovy scripts - use template design patterns to extract dynamic code of business logic and add it to Groovy; S2. Introduce GroovyClassLoader, load it into JAVA's JVM, and call it; S3, referenced symbolic link - in the JVM, the qualified name of the newly loaded class Class is replaced; S4, use symbolic links to save reference pointers of the new and old classes; S5. Monitor container configuration files - use the configuration center to implement centralized management and dynamic refresh of configurations; S6. Code hot deployment - make configuration changes through the configuration center and send change notifications to the server; S7. The server performs a reinitialization operation of the Groovy object. After the initialization is completed, the Groovy object is returned to the server, and a success notification is sent to the configuration center through the server to complete the deployment.

2. The code hot deployment method based on Groovy and configuration center according to claim 1 is characterized in that: The dynamic code of the business logic is extracted by using a template design pattern to define a Java template class, and extracting the dynamic code of the business logic through the Java template class; The Java template class contains a skeleton for executing business logic and a loadClass method for calling a Groovy script.

3. The code hot deployment method based on Groovy and configuration center according to claim 1 is characterized in that: The GroovyClassLoader is introduced to load the Groovy script into the JVM of JAVA, and call and execute it to form a new class Class.

4. The code hot deployment method based on Groovy and configuration center according to claim 3 is characterized in that: The replacement of the qualified name is used to rename the newly loaded class Class and distinguish between the new and old Class.

5. The code hot deployment method based on Groovy and configuration center according to claim 4 is characterized in that: The symbolic link method is used to save the reference pointers of the new and old classes, which is used to directly replace the reference when the class is rewritten and loaded and the class name changes.

6. The code hot deployment method based on Groovy and configuration center according to claim 1 is characterized in that: The monitoring container configuration file comprises the following steps: S51. Through the configuration monitoring function of the configuration center, the changes of the groovy script can be perceived in real time; S52. Reload the Groovy script source code when the configuration changes; S53. Recompile the Groovy script.

7. The code hot deployment method based on Groovy and configuration center according to claim 6 is characterized in that: In S51, the configuration monitoring function is implemented by using an event monitor to monitor changes in the groovy script configuration.

8. The code hot deployment method based on Groovy and configuration center according to claim 1 is characterized in that: The configuration center, after receiving the success notification, generates modification success feedback through the configuration center.

9. The code hot deployment method based on Groovy and configuration center according to any one of claims 1 to 8, characterized in that: The configuration center is Spring Cloud Config or Nacos.

Citation Information

Cited By

  • Interface verification method and system based on script hot update and program product

    CN122331924A