Movatterモバイル変換


[0]ホーム

URL:


CN113419741B - Online interface code generation method based on Springboot - Google Patents

Online interface code generation method based on Springboot
Download PDF

Info

Publication number
CN113419741B
CN113419741BCN202110807233.2ACN202110807233ACN113419741BCN 113419741 BCN113419741 BCN 113419741BCN 202110807233 ACN202110807233 ACN 202110807233ACN 113419741 BCN113419741 BCN 113419741B
Authority
CN
China
Prior art keywords
micro
service
control end
main control
code
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202110807233.2A
Other languages
Chinese (zh)
Other versions
CN113419741A (en
Inventor
吴志雄
陈大耀
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Linewell Software Co Ltd
Original Assignee
Linewell Software Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Linewell Software Co LtdfiledCriticalLinewell Software Co Ltd
Priority to CN202110807233.2ApriorityCriticalpatent/CN113419741B/en
Publication of CN113419741ApublicationCriticalpatent/CN113419741A/en
Application grantedgrantedCritical
Publication of CN113419741BpublicationCriticalpatent/CN113419741B/en
Activelegal-statusCriticalCurrent
Anticipated expirationlegal-statusCritical

Links

Images

Classifications

Landscapes

Abstract

The invention relates to an online interface code generation method based on a Springboot. Providing a distributed micro-service system based on SpringBoot, which comprises a main control end and a plurality of micro-service client ends; the main control end is used for generating source codes, distributing the source codes to the micro service clients, initiating operation including hot update, and receiving processing results of the micro service clients; and the micro-service client is used for receiving the source code, pre-compiling the check code to check whether the code is compiled successfully or not, finally executing hot update to reload the Spring boot context, loading the Class with the source code compiled successfully into IoC of Spring, and registering the Class as Spring service for calling. In the environment of a micro-service distributed system, the source codes can be quickly generated and sent according to the prefabricated code modules without the processes of redevelopment, test and deployment; and the hot update supports the distributed micro-service system, the program only restarts the SpringBoot application context, and the process is not restarted, so that the deployment speed is accelerated.

Description

Online interface code generation method based on Springboot
Technical Field
The invention relates to the technical field of universal interface code generation and hot update in data center open service, in particular to an online interface code generation method based on a Springboot.
Background
In the data center open service, an interface for changing the data center is released after being tested and packaged after being developed by developers, and the flow is long. Especially, when developing some common interfaces, it is time consuming and labor consuming.
The existing hot update technology such as devtool is based on a single JVM process, and source codes are compiled into IDE (integrated development environment), so that hot loading is carried out after class, and the hot loading technology is mainly used for accelerating development and reducing the time for repeatedly restarting the JVM process.
Disclosure of Invention
The invention aims to provide an online interface code generation method based on a Springboot, which can quickly generate source codes and send the source codes to a server according to a prefabricated code module under the environment of a micro-service distributed system without the processes of redevelopment, test and deployment; and the hot update supports the distributed micro-service system, the program only restarts the SpringBoot application context, and the process is not restarted, so that the deployment speed is accelerated.
In order to achieve the purpose, the technical scheme of the invention is as follows: an online interface code generation method based on a Springboot provides a distributed micro-service system based on the Springboot, and comprises a main control end and a plurality of micro-service clients; wherein,
the main control end is used for generating source codes, distributing the source codes to the micro-service clients, initiating operation including hot updating, and receiving processing results of the micro-service clients;
and the micro-service client is used for receiving the source code, pre-compiling the check code to check whether the code is compiled successfully or not, finally executing hot update to reload the Spring boot context, loading the Class with the source code compiled successfully into IoC of Spring, and registering the Class as Spring service for calling.
In an embodiment of the present invention, the method specifically includes the following steps:
step 1, starting TCP connection service:
the method comprises the steps that when a main control end is started, a TCP service port is automatically started;
when the micro-service client is started, the micro-service client is automatically connected with a TCP (transmission control protocol) service port of the main control end and registers own information to the main control end, and a communication link is provided for RPC (remote procedure call) calling between the main control end and the micro-service client;
step 2, after the TCP connection service is established between the main control end and the micro-service client, the main control end generates source codes:
generating a universal source code at the main control end according to the code template or compiling a code on line at the main control end, and generating a source code at the main control end;
and step 3, grouping source codes:
the master control end groups the generated source codes according to the category of the micro service client and packs the codes belonging to the same micro service client;
step 4, source code distribution:
the master control end sends RPC requests for distributing source codes to the micro-service client end in sequence according to the dependency relationship of the micro-service, and waits for the return of a result;
step 5, when the micro-service client receives an RPC request for distributing source codes, sending the received source code data into a custom ClassLoader for compiling, obtaining a class object after successful compiling, verifying the correctness of the source codes, finally caching the source codes into a memory, and returning an execution result to the main control end;
step 6, the master control end receives RPC request results of the distribution source codes returned by all the microservice clients, judges whether the execution of the distribution source codes is successful or not according to the returned results, and if one of the results is failed, the flow is stopped and the failure is returned; if all the operations are successful, the next operation is carried out;
step 7, the master control end sequentially sends hot update RPC requests to the micro-service client end according to the sequence required by the source code module, and waits for the result to return;
step 8, when the micro-service client receives the RPC request of the hot update, triggering and executing a hot update function module, and preparing the system to execute the hot update;
and 9, the micro-service client executes hot updating, closes the context of the Spring boot application, closes all the components injected into the Spring, and closes the thread and the thread pool.
In an embodiment of the present invention, the method further includes a step of clearing the cache, that is, all the cache data in the static class is cleared in a reflection manner, so as to avoid memory leakage.
In an embodiment of the present invention, the step of clearing the cache is specifically implemented as follows:
step 10, the microservice client checks all current threads to confirm the threads needing to be closed, and finally executes destruction operation on all found threads to be closed to release resources;
step 11, the micro-service client starts an application process, writes all the issued source codes into a cache file from a cache, and automatically compiles and loads all the codes during cold start; creating a self-defined ClassLoader and setting the self-defined ClassLoader as the ClassLoader of the current thread so as to take over the loading of jar packages and class files when the system is started, and distributing the class Loader used by the system according to rules to ensure that the system is normally started;
step 12, reading all source codes from the source code cache by using the currently self-defined ClassLoader, and compiling the source codes into class to be written to a local path, so that the ClassLoader can correctly load the class;
step 13, starting the SpringBoot application context, loading class compiled from a source code and injecting the class into a Spring container in a service mode, wherein a module of the system can directly call the code; when the micro service client finishes the hot updating, returning a result of executing the hot updating to the main control end;
and step 14, the main control end receives the hot updating results of all the microservice clients, if one microservice client fails, the flow is stopped, the microservice client fails to return, and if all the microservice client fails, the microservice client succeeds in operation.
In one embodiment of the invention, in step 1, the master control end can call the micro-service client through RPC; the micro-service client can also call the master control end through the RPC, and the RPC calls at the two sides of the master control end and the micro-service client share one TCP link, so that the deployment difficulty of the system is reduced.
In an embodiment of the present invention, in step 5, the ClassLoader is implemented based on Groovy.
Compared with the prior art, the invention has the following beneficial effects:
1. under the environment of a micro-service distributed system, according to a prefabricated code module, a source code can be quickly generated and sent without the processes of redevelopment, test and deployment;
2. the hot update supports the distributed micro-service system, the program only restarts the SpringBoot application context, and the process is not restarted, so that the deployment speed is accelerated.
Drawings
FIG. 1 is a flow chart of the method of the present invention.
Detailed Description
The technical scheme of the invention is specifically explained below with reference to the accompanying drawings.
The invention relates to an online interface code generation method based on a Springboot, which provides a distributed micro-service system based on the Springboot, and comprises a master control end and a plurality of micro-service client ends; wherein,
the main control end is used for generating source codes, distributing the source codes to the micro-service clients, initiating operation including hot updating, and receiving processing results of the micro-service clients;
and the micro-service client is used for receiving the source code, pre-compiling the check code to check whether the code is compiled successfully or not, finally executing hot update to reload the Spring boot context, loading the Class with the source code compiled successfully into IoC of Spring, and registering the Class as Spring service for calling.
The following are specific implementation examples of the present invention.
As shown in fig. 1, in the present invention, a distributed micro-service system based on SpringBoot is divided into a master control end and a plurality of micro-service clients. Wherein,
and the master control end is used for generating source codes, distributing the source codes to the micro service clients, initiating operations such as hot update and the like, and receiving the processing results of the micro service clients.
And the micro-service client is used for receiving the source code, pre-compiling the check code to check whether the code is compiled successfully or not, finally executing hot update to reload the Spring boot context, loading the Class with the source code compiled successfully into IoC of Spring, and registering the Class as Spring service for calling.
The technical scheme provided by the invention is realized by adopting the following scheme: the online interface code generation method based on the SpringBoot distributed micro-service system specifically comprises the following steps:
step 1, starting TCP connection service.
The method comprises the steps that when a main control end is started, a TCP server is automatically started;
when the micro-service client is started, the micro-service client is automatically connected with a TCP (transmission control protocol) service port of the main control end and registers own information to the main control end, and a communication link is provided for RPC (remote procedure call) calling between the main control end and the micro-service client.
The main control end can call the micro-service client through RPC; the micro-service client can also call the master control end through the RPC, the scheme provided by the proposal is summarized, and the two-sided RPC calls share one TCP link, so that the deployment difficulty of the system can be well reduced.
And 2, after the TCP connection service is established between the main control end and the micro-service client, the main control end generates source codes.
And generating a universal source code at the main control end according to the code template or writing a code on line at the main control end, and generating the source code at the main control end.
And step 3, grouping the source codes.
And the master control end groups the generated source codes according to the category of the source codes and the category of the micro service end and packs the codes belonging to the same micro service end.
And 4, distributing source codes.
And the master control end sends the RPC requests for distributing the source codes to the micro-service client end in sequence according to the dependency relationship of the micro-service, and waits for the return of the result.
And 5, when the micro-service client receives an RPC request for distributing the source code, sending the received source code data to a custom ClassLoader (based on Groovy) for compiling, obtaining a class object after successful compiling, verifying the correctness of the source code, finally caching the source code into a memory, and returning an execution result to the main control terminal.
And 6, the master control end receives RPC request results of the distributed source codes returned by all the microservice clients, judges whether the execution of the distributed source codes is successful or not according to the returned results, if one of the RPC request results fails, the flow is stopped, the RPC request results are returned, and if all the RPC request results are successful, the next operation is carried out.
And 7, the master control end sequentially sends hot update RPC requests to the micro-service client end according to the sequence required by the source code module, and waits for the result to be returned.
And 8, when the micro-service client receives the RPC request of the hot update, triggering to execute the hot update function module, and preparing the system to execute the hot update.
And 9, the micro-service client executes hot updating, closes the context of the Spring boot application, closes all the components injected into the Spring, and closes the thread and the thread pool.
In the technical solution of the present disclosure, in a preferred implementation manner, the method further includes clearing the cache.
Because some static classes cache data and the memory leakage is caused by hot updating, the cache data in the static classes are completely cleared by adopting a reflection mode, and the memory leakage is avoided.
Step 10, the micro-service client does not close the opened threads or thread pools when some components are closed, and needs to check all current threads again to confirm which threads need to be closed, and finally executes destroy operation on all found threads to be closed, and releases resources.
And step 11, the micro-service client starts an application process, writes all the issued source codes into a cache file from a cache, and automatically compiles and loads all the codes during cold start. And creating a self-defined ClassLoader and setting the self-defined ClassLoader as the ClassLoader of the current thread so as to take over the loading of the jar packet and the class file when the system is started, and distributing the class Loader used by the system according to rules so as to normally start the system.
And step 12, reading all source codes from the source code cache by using the currently self-defined ClassLoader, and compiling the source codes into class to be written to a local path, so that the ClassLoader can correctly load the class.
And step 13, starting the SpringBoot application context, loading class compiled from the source code and injecting the class into a Spring container in a service mode, wherein a module of the system can directly call the code. And returning the result of executing the hot update to the main control terminal.
And step 14, the main control end receives the hot updating results of all the microservice clients, if one microservice client fails, the flow is stopped, the microservice client fails to return, and if all the microservice client fails, the microservice client succeeds in operation.
The invention has the following characteristics:
1. the main control end is connected with the micro-service client through a TCP to complete the two-way request of the RPC.
2. The generated source codes are grouped according to the functions of the micro-service client, and the source codes are sequentially sent to the micro-service client to be precompiled so as to verify the correctness of the source codes.
3. The main control end sends hot update requests to the micro service client end in sequence, the micro service client end executes a hot update processing program and returns results to the main control end, and finally the main control end manages the whole process.
The above are preferred embodiments of the present invention, and all changes made according to the technical scheme of the present invention that produce functional effects do not exceed the scope of the technical scheme of the present invention belong to the protection scope of the present invention.

Claims (5)

CN202110807233.2A2021-07-162021-07-16Online interface code generation method based on SpringbootActiveCN113419741B (en)

Priority Applications (1)

Application NumberPriority DateFiling DateTitle
CN202110807233.2ACN113419741B (en)2021-07-162021-07-16Online interface code generation method based on Springboot

Applications Claiming Priority (1)

Application NumberPriority DateFiling DateTitle
CN202110807233.2ACN113419741B (en)2021-07-162021-07-16Online interface code generation method based on Springboot

Publications (2)

Publication NumberPublication Date
CN113419741A CN113419741A (en)2021-09-21
CN113419741Btrue CN113419741B (en)2022-05-27

Family

ID=77721799

Family Applications (1)

Application NumberTitlePriority DateFiling Date
CN202110807233.2AActiveCN113419741B (en)2021-07-162021-07-16Online interface code generation method based on Springboot

Country Status (1)

CountryLink
CN (1)CN113419741B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN116149790B (en)*2023-02-152023-11-21北京景安云信科技有限公司Method for starting multiple Springboot items based on JVM process reduction
CN116185373B (en)*2023-04-262023-09-01上海金仕达软件科技股份有限公司Micro-service infrastructure generation method based on static code analysis

Citations (3)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN106648717A (en)*2015-11-032017-05-10陈智玲Network real-time programming development method for microcontroller
CN106991035A (en)*2017-04-062017-07-28北京计算机技术及应用研究所A kind of Host Supervision System based on micro services framework
CN108664239A (en)*2018-05-212018-10-16中信百信银行股份有限公司A kind of across technology stack web front-end development system and method based on micro services

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
US10620947B2 (en)*2018-02-152020-04-14Wipro LimitedMethod and system for migrating monolithic enterprise applications to microservice architecture

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN106648717A (en)*2015-11-032017-05-10陈智玲Network real-time programming development method for microcontroller
CN106991035A (en)*2017-04-062017-07-28北京计算机技术及应用研究所A kind of Host Supervision System based on micro services framework
CN108664239A (en)*2018-05-212018-10-16中信百信银行股份有限公司A kind of across technology stack web front-end development system and method based on micro services

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
"基于SpringBoot的代码自动生成";乐乐姐;《CSDN,https://blog.csdn.net/qq_20735197/article/details/103196617》;20191122;第1-8页*

Also Published As

Publication numberPublication date
CN113419741A (en)2021-09-21

Similar Documents

PublicationPublication DateTitle
US8151277B2 (en)Method and system for dynamic remote injection of in-process agents into virtual machine based applications
US7904886B2 (en)Method for executing an application in a virtual container forming a virtualized environment session
EP1508858A2 (en)A method and system for executing software on non-native platforms
US5933639A (en)System and method for debugging distributed programs
US6263456B1 (en)System for remote debugging of client/server application
Pina et al.Mvedsua: Higher availability dynamic software updates via multi-version execution
CN113419741B (en)Online interface code generation method based on Springboot
CN109766269A (en) Continuous integration automated testing methods, devices, equipment and media
US6839647B2 (en)Same virtual machine mode for distributed test execution
CN108845812A (en)Update of plug-in method, apparatus, computer equipment and storage medium
US11960869B2 (en)Android penetration method and device for implementing silent installation based on accessibility services
CN115659343B (en)Container attack simulation method and detection method for simulating real attack, and terminal
US7395526B2 (en)Method and system for managing application server lifecycle
CN113760339A (en)Vulnerability repair method and device
CN114546843A (en)Program debugging processing method and device
CN105159712B (en)Interface starting method and device
CN113127329B (en) Script debugging method, device and computer storage medium
CN109408133A (en)A kind of method and apparatus starting component
CN111400162A (en)Test method and test system
CN117555645A (en)Data processing method, device, equipment and medium based on multi-terminal application platform
CN118170420A (en) A code management method, system and computing device
CN113986744B (en)Method and device for testing sub-library sub-table assembly and storage medium
CN113805911A (en)Multi-version program management method, device and system of server side
CN110928569A (en)Method for realizing Live Update function of communication equipment
CN114706662B (en)Method and system for realizing dynamic simulation of business operation and data based on JVM sandbox

Legal Events

DateCodeTitleDescription
PB01Publication
PB01Publication
SE01Entry into force of request for substantive examination
SE01Entry into force of request for substantive examination
GR01Patent grant
GR01Patent grant

[8]ページ先頭

©2009-2025 Movatter.jp