A code hot deployment method and device, electronic equipment and storage medium

By dynamically loading classes and using tracking mechanisms, dynamic deployment and rapid response of code are achieved, solving the problem of cumbersome traditional release processes and improving development efficiency and user experience.

CN121300810BActive Publication Date: 2026-05-01QIJIAYOUDAO NETWORK TECH (BEIJING) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
QIJIAYOUDAO NETWORK TECH (BEIJING) CO LTD
Filing Date
2025-12-15
Publication Date
2026-05-01

AI Technical Summary

Technical Problem

Traditional code deployment processes are cumbersome, leading to wasted development resources, poor user experience, and an inability to respond promptly to changes in business requirements.

Method used

By defining dynamically loaded parent and child classes, combined with tracking business interfaces and annotation identifiers, the target interface is dynamically loaded, enabling dynamic compilation and deployment of the code, which takes effect immediately without restarting the application.

Benefits of technology

It enables code modifications to take effect immediately, quickly responding to business needs without cumbersome deployment processes, saving time and resources, and improving user experience and system availability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121300810B_ABST
    Figure CN121300810B_ABST
Patent Text Reader

Abstract

The application discloses a code hot deployment method, comprising the following steps: defining a dynamic loading parent class to realize a target interface needing a dynamic loading function; defining a dynamic loading subclass; defining a buried point business interface and a class for realizing the buried point business interface; when an implementation method of the class for realizing the buried point business interface is executed, determining a target dynamic loading subclass according to a buried point business interface identifier; when an abstract value in a function table of the target dynamic loading subclass is changed, obtaining updated target dynamic loading source code according to a function identifier code of the abstract value; creating a bean and loading the bean into a spring container; and acquiring the bean according to the function identifier code when calling, so as to call the target dynamic loading subclass. Through the dynamic loading class and the buried point mechanism, the application realizes that the code modification takes effect directly, and does not need to pass through a complicated code publishing process, thereby improving the efficiency of dynamic adjustment of the code. The application also discloses a device, an electronic equipment and a storage medium for realizing the method.
Need to check novelty before this filing date? Find Prior Art

Description

A method, apparatus, electronic device, and storage medium for hot code deployment. Technical Field

[0001] This invention relates to the field of computer technology, and in particular to a method, apparatus, electronic device, and storage medium for hot code deployment. Background Technology

[0002] In the modern software development field, with the rapid iteration of business needs and the continuous improvement of user expectations, the update frequency of software systems has increased significantly. However, traditional code release processes typically involve multiple lengthy steps, including committing code to a version control system (such as Git), automated or manual building (such as generating executable files using tools like Maven / Gradle), packaging (such as generating deployment packages in DAR / JAR / WAR formats), environment configuration verification, and final deployment (such as pushing to test / production servers via a CI / CD pipeline and restarting the service). This series of processes results in a long overall cycle and huge resource consumption.

[0003] As business models evolve towards agility and refinement, some business modules exhibit characteristics of frequent, small-scale changes—such as adjustments to the start and end times of promotional activities, real-time optimization of user tagging systems, and dynamic corrections to risk control thresholds. These update needs may occur on an hourly or even minute-by-minute basis. However, under traditional deployment methods, each minor modification triggers a complete build-package-deployment chain, leading to inefficient waste of development resources. Code changes cannot take effect immediately, requiring redeployment of the entire application, resulting in business interruptions and impacting user experience. This makes it difficult for development teams to respond promptly to the market's demands for rapid product iteration. Summary of the Invention

[0004] To address the aforementioned problems in the prior art, this invention provides a code hot deployment method, apparatus, electronic device, and storage medium. The technical problem to be solved by this invention is achieved through the following technical solution:

[0005] The first aspect of this invention provides a method for hot code deployment, comprising the following steps:

[0006] Define a dynamic loading parent class to implement the target interface that requires dynamic loading functionality;

[0007] Define a dynamically loaded subclass to implement the target interface; wherein the dynamically loaded subclass inherits the methods of the dynamically loaded parent class;

[0008] Define a tracking point business interface and a class that implements the tracking point business interface; wherein, the tracking point business interface uses annotations to identify the dynamic loading function and the tracking point business interface identifier, and the tracking point business interface identifier corresponds to the dynamic loading subclass;

[0009] When the implementation method of the class of the event tracking business interface is executed, the target dynamically loaded subclass is determined according to the event tracking business interface identifier;

[0010] Determine whether the summary value in the function table of the target dynamically loaded subclass has changed;

[0011] If so, then obtain the updated target dynamic loading source code of the target dynamic loading subclass according to the function identifier code of the digest value;

[0012] Dynamically load the source code to create beans based on the target and load them into the Spring container;

[0013] When invoked, the bean is obtained based on the function identifier code, and the target dynamically loads the subclass.

[0014] In one embodiment of the present invention, the step of dynamically loading the source code according to the target to create a bean and loading it into the Spring container includes:

[0015] Generate the class identifier name of the target dynamically loaded source code;

[0016] The target's dynamically loaded source code is compiled into bytecode.

[0017] The bytecode is loaded into the compiler's class loader based on the class identifier name, and an object of the class is returned.

[0018] Create a bean based on the object and load it into the Spring container.

[0019] In one embodiment of the present invention, the target interface includes: a preprocessing interface, a surround processing interface, and / or a postprocessing interface.

[0020] In one embodiment of the present invention, the method further includes:

[0021] Execute user business data processing requests; whereby user business data processing requests include instructions and user information;

[0022] During the execution of a user's business data processing request, the system determines whether the user has permission to call the data tracking interface based on the user information.

[0023] If so, execute the implementation method of the class of the aforementioned data tracking business interface.

[0024] A second aspect of the present invention provides a code hot deployment apparatus, comprising:

[0025] The first definition module is used to define the target interface that requires dynamic loading functionality by defining the parent class for dynamic loading.

[0026] The second definition module is used to define dynamically loaded subclasses to implement the target interface; wherein the dynamically loaded subclasses inherit the methods of the dynamically loaded parent class;

[0027] The third definition module is used to define the tracking business interface and the class that implements the tracking business interface; wherein, the tracking business interface uses annotations to identify the dynamic loading function and the tracking business interface identifier, and the tracking business interface identifier corresponds to the dynamic loading subclass;

[0028] The determination module is used to determine the target dynamically loaded subclass based on the tracking point business interface identifier when the implementation method of the class of the tracking point business interface is executed.

[0029] The judgment module is used to determine whether the summary value in the function table of the target dynamically loaded subclass has changed;

[0030] The acquisition module is used to acquire the updated target dynamic loading source code of the target dynamic loading subclass according to the function identifier code of the digest value if the condition is met.

[0031] Create a loading module to dynamically load source code, create beans, and load them into the Spring container based on the target.

[0032] The calling module is used to obtain the bean based on the function identifier code when calling, so as to dynamically load the subclass of the target.

[0033] In one embodiment of the present invention, the step of dynamically loading the source code according to the target to create a bean and loading it into the Spring container includes:

[0034] Generate the class identifier name of the target dynamically loaded source code;

[0035] The target's dynamically loaded source code is compiled into bytecode.

[0036] The bytecode is loaded into the compiler's class loader based on the class identifier name, and an object of the class is returned.

[0037] Create a bean based on the object and load it into the Spring container.

[0038] In one embodiment of the present invention, the target interface includes: a preprocessing interface, a surround processing interface, and / or a postprocessing interface.

[0039] In one embodiment of the present invention, it further includes:

[0040] The first execution module is used to execute the user's business data processing request; wherein, the user's business data processing request includes instructions and user information;

[0041] The permission module is used to determine whether a user has permission to call the data tracking interface based on the user information during the execution of a user's business data processing request.

[0042] The second execution module is used to execute the implementation method of the class of the data tracking business interface, if applicable.

[0043] A third aspect of the present invention provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement a code hot deployment method provided in the first aspect of the present invention.

[0044] A fourth aspect of the present invention provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements a code hot deployment method provided in the first aspect of the present invention.

[0045] The beneficial effects of this invention are:

[0046] This invention utilizes a dynamic class loading mechanism to implement target interfaces and implement tracking points, enabling the dynamic deployment and loading of code for critical business nodes. By dynamically compiling and deploying code at key business logic points, code modifications take effect immediately, allowing for rapid response to changes in business requirements. This eliminates the need for cumbersome code deployment processes, allowing developers to quickly modify and test code locally, saving significant time and effort. Furthermore, it reduces server resource consumption and network bandwidth usage caused by frequent deployments, lowering operational costs. Simultaneously, the immediate effect of code modifications without requiring application restarts or business interruptions improves user experience and system availability. Moreover, it enables rapid response to changes in business requirements, allowing for dynamic code adjustment and optimization to adapt to changing business environments.

[0047] Other features and advantages of the invention will be set forth in the description which follows, and will be apparent in part from the description, or may be learned by practicing the invention. The objects and other advantages of the invention may be realized and obtained by means of the structures particularly pointed out in the written description, claims, and drawings.

[0048] The technical solution of the present invention will be further described in detail below with reference to the accompanying drawings and embodiments. Attached Figure Description

[0049] The accompanying drawings are provided to further illustrate the invention and form part of the specification. They are used in conjunction with embodiments of the invention to explain the invention and do not constitute a limitation thereof. In the drawings:

[0050] Figure 1 is a flowchart illustrating a code hot deployment method provided in an embodiment of the present invention;

[0051] Figure 2 is a block diagram of a code hot deployment device provided in an embodiment of the present invention. Detailed Implementation

[0052] The present invention will be further described in detail below with reference to specific embodiments, but the implementation of the present invention is not limited thereto.

[0053] As shown in Figure 1, a first aspect of the present invention provides a code hot deployment method, comprising the following steps:

[0054] Step 11: Define a dynamic loading parent class to implement the target interface that requires dynamic loading functionality.

[0055] Step 12: Define dynamically loaded subclasses to implement the target interface.

[0056] Among them, the dynamic loading subclass inherits the dynamic loading parent class's method.

[0057] Step 13: Define the event tracking business interface and the class that implements the event tracking business interface.

[0058] Among them, the tracking point business interface uses annotations to identify the dynamic loading function and the tracking point business interface identifier, and the tracking point business interface identifier and the dynamic loading subclass form a corresponding relationship.

[0059] Step 14: When the implementation method of the class of the tracking business interface is executed, the target dynamic subclass is dynamically loaded based on the tracking business interface identifier.

[0060] Step 15: Determine whether the summary value in the function table of the target dynamically loaded subclass has changed.

[0061] Step 16: If yes, then obtain the updated target dynamic loading source code of the target dynamic loading subclass based on the function identifier code of the digest value.

[0062] Step 17: Dynamically load the source code according to the target to create a bean and load it into the Spring container.

[0063] Step 18: When calling, obtain the bean based on the function identifier code, and dynamically load the subclass of the calling target.

[0064] In this embodiment, by dynamically loading the target interface of the class and using a tracking mechanism, the code of key business nodes can be dynamically deployed and loaded. By dynamically compiling and deploying the code at critical business logic points, code modifications take effect immediately, enabling rapid response to changes in business requirements without the need for cumbersome code release processes. Developers can quickly modify and test code locally, saving significant time and effort. Furthermore, it reduces server resource consumption and network bandwidth usage caused by frequent releases, lowering operating costs. Simultaneously, code modifications take effect immediately without requiring application restarts or business interruptions, improving user experience and system availability. In addition, it allows for rapid response to changes in business requirements, enabling dynamic code adjustment and optimization to adapt to changing business environments.

[0065] Based on the first aspect of the present invention, the second aspect of the present invention provides a code hot deployment method in further detail, comprising the following steps:

[0066] Step 21: Execute the user's business data processing request.

[0067] The user's business data processing requests include instructions and user information.

[0068] In this step, the user's request is a request that requires business data processing, such as viewing or statistically analyzing the user's business data, or modifying the user's business data. Specifically, the user's business data processing request is received first, and then the request is executed.

[0069] Here, in order to meet the requirement that the code of the business nodes can be dynamically compiled and deployed, steps A1-A3 need to be executed in advance for deployment before receiving user business data processing requests:

[0070] Step A1: Define a dynamic loading parent class to implement the target interface that requires dynamic loading functionality.

[0071] The target interfaces include: a pre-processing interface, an around-processing interface, and / or a post-processing interface. The pre-processing, around-processing, and post-processing interfaces represent the three advice types (@Before, @Around, and @After) used in Spring AOP within a Spring Boot project. In actual plugin development, the appropriate Handler class to implement can be selected based on the plugin's business requirements and scenario. Accordingly, three dynamically loaded parent classes are defined: DynamicBeforeHandler, DynamicAroundHandler, and DynamicAfterHandler.

[0072] Among them, DynamicBeforeHandler corresponds to the @Before notification type:

[0073] Execution timing: Preprocessing, before the target method is called;

[0074] Purpose: To record logs, verify permissions, and prepare preliminary data, etc.

[0075] DynamicAroundHandler corresponds to the @Around notification type:

[0076] Execution timing: Around processing, the "entire process" of the around target method;

[0077] Applications: Implementing transaction control, measuring execution time, implementing caching, and unifying exception handling, etc.

[0078] DynamicAfterHandler corresponds to the @After notification type:

[0079] Execution timing: Post-processing, executed regardless of whether the target method succeeds or throws an exception (equivalent to finally);

[0080] Purpose: To release resources, record the end of method execution, etc.

[0081] DynamicBeforeHandler, DynamicAroundHandler, and DynamicAfterHandler each hold references to the BeforeHandler, AroundHandler, and AfterHandler interfaces, respectively. The definitions of these three interfaces are shown in the following example:

[0082] public enum EPointcutEvent {

[0083] BEFORE(1, "Preprocessing"),

[0084] AROUND(2, "Wrap around processing"),

[0085] AFTER(3,"Post-processing");

[0086] }

[0087] EPointcutEvent.BEFORE corresponds to the BeforeHandler.java interface.

[0088] EPointcutEvent.AROUND corresponds to the AroundHandler.java interface.

[0089] EPointcutEvent.AFTER corresponds to the AfterHandler.java interface.

[0090] public interface BeforeHandler extends Activable, Sortable,Functional {

[0091] XRequest beforeRequest(XContext xcontext, Object[] params);

[0092] }

[0093] public interface AroundHandler extends Activable, Sortable,Exceptional, Functional {

[0094] XResponse around(XContext xcontext, Object[] params);

[0095] }

[0096] public interface AfterHandler extends Activable, Sortable, Functional{

[0097] XResponse afterResponse(XContext xcontext, Object[] params, Objectresult);

[0098] }

[0099] Here's an example of code that defines a dynamically loaded parent class to implement the target interface that requires dynamic loading functionality, using the dynamically loaded parent class DynamicBeforeHandler as an example:

[0100] @Service

[0101] @Scope("prototype")

[0102] public class DynamicBeforeHandler implements BeforeHandler, Dynamical{

[0103] private XFunction function;

[0104] private BeforeHandler handler;

[0105] @Override

[0106] public XRequest beforeRequest(XContext context, Object[] params){

[0107] context.setFunction(function);

[0108] return handler.beforeRequest(context, params);

[0109] }

[0110] }

[0111] Step A2: Define dynamically loaded subclasses to implement the target interface.

[0112] Among them, the dynamic loading subclass inherits the dynamic loading parent class's method.

[0113] In this step, we define code to dynamically load subclasses to implement the target interface. Taking the afterHandler interface as an example, we define a dynamically loaded subclass GetChartDataDynamicAfterHandler that implements the afterHandler interface.

[0114] The code `resultBO.setSupportRadio(1);` displays year-on-year and month-on-month information in the statistical chart. Example:

[0115] @Component

[0116] public class GetChartDataDynamicAfterHandler implements AfterHandler{

[0117] @Override

[0118] public XResponse afterResponse(XContext xcontext, Object[] params,Object result) {

[0119] XResponse xResponse = new XResponse(result);

[0120] if (result == null) {

[0121] return xResponse;

[0122] }

[0123] StatisticChartDataBO resultBO = (StatisticChartDataBO)result;

[0124] resultBO.setSupportRadio(1);

[0125] return xResponse;

[0126] }

[0127] }

[0128] Step A3: Define the event tracking business interface and the class that implements the event tracking business interface.

[0129] Among them, the tracking point business interface uses annotations to identify the dynamic loading function and the tracking point business interface identifier, and the tracking point business interface identifier and the dynamic loading subclass form a corresponding relationship.

[0130] In this step, the implementation method of the tracking business interface class is the specific business implementation method of the business that needs tracking. The tracking business interface requiring dynamic loading functionality is marked with annotations to indicate that the tracking has dynamic loading capabilities, facilitating subsequent identification. The tracking business interface identifier is a unique ID representing the tracking business interface. The correspondence between the tracking business interface identifier and the dynamically loaded subclass is the dynamically loaded subclass that the tracking business interface needs or can call (use), and this correspondence is stored in the database. The tracking business interface identifier can correspond to one or more target dynamically loaded subclasses. For example, in this embodiment, the tracking business interface identifier can correspond to one, two, or all three target dynamically loaded subclasses.

[0131] For example, the code for defining the event tracking business interface and implementing the event tracking business interface is as follows:

[0132] public interface IChartRadioService {

[0133] StatisticChartDataBO supportRadio(String headId, String companyId,StatisticChartDataBO statisticChartDataBO);

[0134] }

[0135] @Slf4j

[0136] @Service

[0137] @XPluginAspect

[0138] public class ChartRadioServiceImpl implements IChartRadioService{

[0139] @Override

[0140] @XPluginPointcut(code = "stat.chart.radio", module = "Smart Data", remark ="Smart Data chart year-on-year and month-on-month comparison")

[0141] public StatisticChartDataBO supportRadio(String headId, StringcompanyId, StatisticChartDataBO statisticChartDataBO) {

[0142] return statisticChartDataBO;

[0143] }

[0144] }

[0145] In the code, the @XPluginAspect annotation identifies the dynamic loading function, and the @XPluginPointcut annotation has a code attribute that identifies a buried point business interface.

[0146] After pre-executing steps A1 - A3, step 21 can be executed after receiving the user's business data processing request.

[0147] Note: Since "智数" is not a commonly known English term, I translated it as "Smart Data" here. You can adjust it according to the actual situation.Step 22: During the execution of the user's business data processing request, determine whether the user has the permission to call the event tracking business interface based on the user information.

[0148] In this step, user information may include form identifiers and user identifiers. Based on this identifier information, it can be determined whether the user has permission to call the event tracking API.

[0149] Step 23: If permissions are available, execute the implementation method of the event tracking business interface class. If permissions are not available, return a permission denied message to the user.

[0150] Step 24: When executing the implementation method of the class of the tracking business interface, determine the target dynamic loading subclass based on the tracking business interface identifier.

[0151] In this step, when executing the implementation method of the tracking business interface class, that is, when calling or using the tracking business interface, if the tracking business interface is annotated with dynamic loading functionality, the database is searched for the target dynamic loading subclass corresponding to the tracking business interface identifier (this can be one or more target dynamic loading subclasses). If the tracking business interface does not have dynamic loading functionality, the implementation method of the tracking business interface class is executed normally.

[0152] Here is a code example of how to execute a user's business data processing request:

[0153] @RestController

[0154] public class StatisticChartCtrl {

[0155] @Autowired

[0156] private IStatStatisticChartBusiness statStatisticChartBusiness;

[0157] @Resource

[0158] private IChartRadioService chartRadioService;

[0159] @PostMapping(" / ajax-get-chart.json")

[0160] public Object ajaxGetChart(@RequestBody StatisticGetChartDataBOgetChartDataBO) {

[0161] StatisticUserInfo userInfo = UserInfoHelper.getUserInfo();

[0162] String headId = userInfo.getHeadId();

[0163] String companyId = userInfo.getHeadCompanyId();

[0164] StatDatasourceChart chartAndResetCondition = statStatisticChartBusiness.getChartAndResetCondition(headId, companyId, userInfo.getAccountId(),getChartDataBO);

[0165] StatisticChartDataBO statisticJustChartBO = statStatisticChartBusiness.getChartData(headId, companyId,userInfo.getAccountId(), getChartDataBO,chartAndResetCondition);

[0166] / / Installation points for business code that requires hot deployment

[0167] StatisticChartDataBO statisticJustChartBOPlug =chartRadioService.supportRadio(headId, companyId, statisticJustChartBO);

[0168] return new AjaxResult(0, "Successfully retrieved", true, statisticJustChartBOPlug);

[0169] }

[0170] }

[0171] The code will have the ability to dynamically load code when it executes chartRadioService.supportRadio.

[0172] Step 25: Determine whether the summary value in the function table of the target dynamically loaded subclass has changed.

[0173] Here, the plugin code is frequently modified and debugged during development. Even after the plugin is released, new versions may be developed, requiring us to monitor whether the plugin code has been modified. Each time the plugin code is committed and saved, an MD5 hash is generated based on the plugin code. This hash is regenerated each time the code is saved, so any change in this hash value indicates that the plugin code has been updated. This means the source code of the dynamically loaded subclass has been updated. The source code of the hot-loaded Java source code is stored in the `function` table in MySQL, and each `sourceCode` has a `functionId` and an MD5 hash value.

[0174] Step 26: If yes, then obtain the updated target dynamic loading source code of the target dynamic loading subclass based on the functionId of the digest value.

[0175] In this step, the previous MD5 value is compared with the current MD5 value. If the current MD5 value has changed, the latest updated source code of the target dynamically loaded subclass is retrieved from the function table using the SQL statement of functionId. This is the updated source code of the target dynamically loaded subclass.

[0176] Step 27: Generate the class identifier name for the target dynamically loaded source code.

[0177] In this step, a unique name, classFullName, is generated for the Java class of the target dynamically loaded source code, ensuring that each dynamically loaded class has a unique identifier and avoiding class loading conflicts.

[0178] For example, the generateDynamicClassName method for generating unique class names is as follows:

[0179] public static String generateDynamicClassName(String sourceCode, longnanoTime) {

[0180] / / Regular expression matches the class name in the class declaration

[0181] Matcher matcher = pattern.matcher(sourceCode);

[0182] / / Check if the class name is found

[0183] if (matcher.find()) {

[0184] String originalClassName = matcher.group(1);

[0185] String newClassName = originalClassName + "_" + nanoTime;

[0186] / / Replace the original class name with the new class name

[0187] return matcher.replaceFirst("class " + newClassName);

[0188] }

[0189] return sourceCode;

[0190] }

[0191] The parameter nanoTime is obtained using System.currentTimeMillis(). For example, the final value of claasFullName generated by the ChartRadioBeforeHandler class is: ChartRadioBeforeHandler_10317680233900.

[0192] Step 28: Compile the target dynamically loaded source code into bytecode.

[0193] In this step, for example, the target dynamically loads the source code using org.codehaus.janino.SimpleCompiler.cook(sourceCode) and compiles the source code into bytecode.

[0194] Example code is as follows:

[0195] SimpleCompiler compiler = new SimpleCompiler();

[0196] compiler.cook(sourceCode).

[0197] Step 29: Load the bytecode into the compiler's class loader based on the class identifier name and return an object of the class.

[0198] In this step, the Java class corresponding to the specified fully qualified class name (classFullName) is dynamically loaded through the class loader associated with the compiler object, and the Class object of that class is returned.

[0199] Example code is as follows:

[0200] Class<?> clazz = compiler.getClassLoader().loadClass(classFullName).

[0201] Step 30: Create a bean based on the object and load it into the Spring container so that it can be managed and injected by Spring.

[0202] Beans are created by wrapping the following code:

[0203] GenericBeanDefinition beanDefinition = new GenericBeanDefinition();

[0204] beanDefinition.setBeanClass(clazz);

[0205] In the following example, loadAndRegisterBean has three parameters: String className, String classFullName, and String sourceCode. These represent the class name, the fully qualified class name, and the plugin source code, respectively. All of these parameters can be obtained in the context after the source code has been detected to have changed.

[0206] Example code is as follows:

[0207] private boolean loadAndRegisterBean(String className, StringclassFullName, String sourceCode) throws Exception {

[0208] SimpleCompiler compiler = new SimpleCompiler();

[0209] compiler.cook(sourceCode);

[0210] Class<?> clazz = compiler.getClassLoader().loadClass(classFullName);

[0211] BeanDefinitionRegistry registry = (BeanDefinitionRegistry) applicationContext.getBeanFactory();

[0212] GenericBeanDefinition beanDefinition = new GenericBeanDefinition();

[0213] beanDefinition.setBeanClass(clazz);

[0214] registry.registerBeanDefinition(className, beanDefinition);

[0215] return true;

[0216] }

[0217] Step 31: When calling, obtain the bean based on the function identifier code, and dynamically load the subclass of the calling target.

[0218] The example code for this step is as follows:

[0219] DynamicBeforeHandler handler = applicationContext.getBean(DynamicBeforeHandler.class);

[0220] handler.setFunction(xFunction);

[0221] handler.setHandler(dynamicLoadingService.reloadBeforeHandler(xFunction)).

[0222] The parameter xFunction object is obtained by querying using the SQL statement (select id, script_code, md5from xrxs_plugin_function where id=#{functionId}).

[0223] In this embodiment, the dynamic loading of class interface definitions and the instrumentation mechanism enable the dynamic replacement and execution of code for critical business nodes. By polling and monitoring changes to interface implementation classes, and promptly compiling and loading the latest code, hot deployment of the code is achieved. Unique names are generated for dynamically loaded classes to avoid class loading conflicts and ensure stable system operation. Dynamically loaded beans are registered in the Spring container, enabling seamless integration with existing Spring applications. Beans of dynamically loaded classes are mapped using functionId, allowing for flexible invocation and management of business logic.

[0224] As shown in Figure 2, a third aspect of the present invention provides a code hot deployment device, comprising:

[0225] The first definition module 41 is used to define the target interface that requires dynamic loading functionality by defining the parent class for dynamic loading.

[0226] The second definition module 42 is used to define dynamically loaded subclasses to implement the target interface; wherein, the dynamically loaded subclasses inherit the methods of the dynamically loaded parent class;

[0227] The third definition module 43 is used to define the tracking business interface and the class that implements the tracking business interface; wherein, the tracking business interface uses annotations to identify the dynamic loading function and the tracking business interface identifier, and the tracking business interface identifier and the dynamically loaded subclass form a corresponding relationship.

[0228] The determination module 44 is used to determine the target dynamically loaded subclass based on the tracking business interface identifier when the implementation method of the class of the tracking business interface is executed.

[0229] Module 45 is used to determine whether the summary value in the function table of the target dynamically loaded subclass has changed;

[0230] Module 46 is used to obtain the updated target dynamic loading source code of the target dynamic loading subclass based on the function identifier code of the digest value if the condition is met.

[0231] Create loading module 47, which is used to dynamically load source code to create beans based on the target and load them into the Spring container;

[0232] Module 48 is called to obtain the bean based on the function identifier code during the call, so that the subclass can be dynamically loaded by the target.

[0233] In one embodiment of the present invention, creating a bean based on the target dynamically loaded source code and loading it into the Spring container includes:

[0234] Generate the class identifier name of the target dynamically loaded source code;

[0235] The target's dynamically loaded source code is compiled into bytecode.

[0236] The bytecode is loaded into the compiler's class loader based on the class identifier name, and an object of the class is returned.

[0237] Create beans from objects and load them into the Spring container.

[0238] In one embodiment of the present invention, the target interface includes: a preprocessing interface, a surround processing interface, and / or a postprocessing interface.

[0239] In one embodiment of the present invention, it further includes:

[0240] The first execution module is used to execute the user's business data processing request; wherein, the user's business data processing request includes instructions and user information;

[0241] The permission module is used to determine whether a user has permission to call the event tracking business interface based on user information during the execution of a user's business data processing request.

[0242] The second execution module is used to execute the implementation methods of the class that implements the tracking point business interface, if applicable.

[0243] A fourth aspect of the present invention provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the code hot deployment method provided by the present invention described above.

[0244] A fifth aspect of the present invention also provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of the code hot deployment method provided in the above-described embodiments of the present invention.

[0245] The memory may include random access memory (RAM) or non-volatile memory (NVM), such as at least one disk storage device. Optionally, the memory may also be at least one storage device located remotely from the aforementioned processor.

[0246] The processors mentioned above can be general-purpose processors, including central processing units (CPUs), network processors (NPs), etc.; they can also be digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware systems.

[0247] The method provided in this invention can be applied to electronic devices. Specifically, the electronic device can be a desktop computer, a portable computer, a smart mobile terminal, a server, etc. No limitation is made herein; any electronic device that can implement this invention falls within the protection scope of this invention.

[0248] For the device / electronic device embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and relevant parts can be referred to in the description of the method embodiments.

[0249] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in one or more blocks of the flowchart illustrations and / or one or more blocks of the block diagrams.

[0250] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means that implement the functions specified in one or more flowcharts and / or one or more block diagrams.

[0251] These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer-implemented process, such that the instructions, which execute on the computer or other programmable apparatus, provide steps for implementing the functions specified in one or more flowcharts and / or one or more block diagrams.

[0252] Obviously, those skilled in the art can make various modifications and variations to this invention without departing from its spirit and scope. Therefore, if these modifications and variations fall within the scope of the claims of this invention and their equivalents, this invention also intends to include these modifications and variations.

Claims

1. A method for hot deployment of code, characterized in that, Includes the following steps: Define a dynamic loading parent class to implement the target interface requiring dynamic loading functionality; define a dynamic loading subclass to implement the target interface; wherein the dynamic loading subclass inherits the methods of the dynamic loading parent class; define an event tracking business interface and a class implementing the event tracking business interface; wherein the event tracking business interface uses the `@XPluginAspect` annotation to identify the dynamic loading functionality and uses the `@XPluginPointcut` annotation to identify the event tracking business interface, and the event tracking business interface identifier corresponds to the dynamic loading subclass; receive user business data processing requests, and then execute the user business data processing requests; in the execution of the request... During the user's business data processing request, the system determines whether the user has permission to call the tracking business interface based on user information. If so, it executes the implementation method of the tracking business interface class. When executing the implementation method of the tracking business interface class, it searches for the corresponding target dynamically loaded subclass in the database based on the tracking business interface identifier. It then determines whether the summary value in the function table of the target dynamically loaded subclass has changed. If so, it obtains the updated target dynamically loaded source code of the target dynamically loaded subclass based on the function identifier code (functionId) of the summary value. Finally, it creates a bean based on the target dynamically loaded source code and loads it into Spring. In the container; upon invocation, a bean is obtained based on the function identifier code to invoke the target dynamically loaded subclass; the step of creating a bean based on the target dynamically loaded source code and loading it into the Spring container includes: generating a class identifier name for the target dynamically loaded source code; compiling the target dynamically loaded source code into bytecode using org.codehaus.janino.SimpleCompiler.cook(sourceCode); where sourceCode represents the target dynamically loaded source code; loading the bytecode into the compiler's class loader compiler.getClassLoader().loadClass() based on the class identifier name, and returning an object of the class; creating a bean based on the object and loading it into the Spring container; the target interface includes: a preprocessing interface, an surround processing interface, and / or a postprocessing interface; where the target interface is the advice type used when using @Aspect in Spring AOP in a Spring Boot project.

2. The method as described in claim 1, characterized in that, The method further includes: executing a user's business data processing request; wherein the user's business data processing request includes instructions and user information; during the execution of the user's business data processing request, determining whether the user has permission to call the tracking point business interface based on the user information; if so, executing the implementation method of the class of the tracking point business interface.

3. A code hot deployment device, characterized in that, include: The first definition module is used to define the target interface that requires dynamic loading functionality by defining the parent class for dynamic loading. The second definition module is used to define a dynamically loaded subclass to implement the target interface; wherein the dynamically loaded subclass inherits the methods of the dynamically loaded parent class; the third definition module is used to define the event tracking business interface and the class implementing the event tracking business interface; wherein the event tracking business interface uses the @XPluginAspect annotation to identify the dynamic loading function and the @XPluginPointcut annotation to identify the event tracking business interface, and the event tracking business interface identifier corresponds to the dynamically loaded subclass; the determination module is used to receive the user's business data processing request and then execute the user's business data processing request; during the execution of the user's business data processing request... The system determines whether a user has permission to call the tracking business interface based on user information; if so, it executes the implementation method of the tracking business interface class; when executing the implementation method of the tracking business interface class, it searches for the corresponding target dynamically loaded subclass in the database based on the tracking business interface identifier; a judgment module is used to determine whether the summary value in the function table of the target dynamically loaded subclass has changed; an acquisition module is used to obtain the updated target dynamically loaded source code of the target dynamically loaded subclass based on the function identifier code (functionId) of the summary value if the change has occurred; and a creation loading module is used to create a bean based on the target dynamically loaded source code and load it into Spring. Within the container; a calling module, used to obtain a bean based on the function identifier code during invocation, to invoke the target dynamically loaded subclass; the step of creating a bean based on the target dynamically loaded source code and loading it into the Spring container includes: generating a class identifier name for the target dynamically loaded source code; compiling the target dynamically loaded source code into bytecode using org.codehaus.janino.SimpleCompiler.cook(sourceCode); where sourceCode represents the target dynamically loaded source code; loading the bytecode into the compiler's class loader compiler.getClassLoader().loadClass() based on the class identifier name, and returning an object of the class; creating a bean based on the object and loading it into the Spring container; the target interface includes: a pre-processing interface, an surround processing interface, and / or a post-processing interface; where the target interface is the advice type used when using @Aspect in Spring AOP in a Spring Boot project.

4. The apparatus as described in claim 3, characterized in that, Also includes: The first execution module is used to execute the user's business data processing request; wherein, the user's business data processing request includes instructions and user information; the permission module is used to determine whether the user has permission to call the tracking point business interface based on the user information during the execution of the user's business data processing request; the second execution module is used to execute the implementation method of the class of the tracking point business interface if the user has permission.

5. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the code hot deployment method as described in any one of claims 1 to 2.

6. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the code hot deployment method according to any one of claims 1 to 2.

Citation Information

Patent Citations

  • Method and device for realizing application hot deployment

    CN110716720A

  • Method and system for realizing hot update dynamic adaptation based on JavaSPI

    CN114880169A