Method for quickly switching program underlying network engine based on SpringBoot framework
By separate operation and packaging projects under the SpringBoot framework, and dynamic filtering of dependencies using custom startup classes and ClassLoader, seamless switching of multiple engines is achieved, solving the complexity and technical threshold of engine switching under the SpringBoot framework, and improving the flexibility and maintainability of the system.
Patent Information
- Application Number
- CN202510928561.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-07
- Publication Date
- 2025-08-01
- Estimated Expiration
- 2045-07-07
AI Technical Summary
Multi-engines under the SpringBoot framework cannot adapt to different scenarios through automatic configuration, resulting in high startup conflicts and technical barriers, and the existing engine switching methods are complex and rely on manual adjustments.
Using separate running projects and packaging projects, through custom startup entrance classes, customized ClassLoader and custom layout manager, the underlying network engine can be quickly switched, dynamically filtered dependent packages, and seamless switching of multiple engines is supported.
It realizes flexible engine switching in the deployment stage, lowers technical threshold, improves system maintainability and flexibility, and reduces storage and maintenance overhead for multi-version packaging.
Smart Images

Figure CN120406920A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of computer software, and particularly to a method for quickly switching the underlying network engine of a program. Background Art
[0002] SpringBoot is an open-source Java development framework based on the Spring framework, aiming to simplify the initial setup and development process of Spring applications. By providing default configurations and automated tools, it reduces the configuration burden on developers and makes it possible to quickly build production-level applications.
[0003] However, its "black box" feature of automatic configuration instead leads to difficulties in debugging. Developers need to deeply understand the underlying mechanisms to solve customization requirements, resulting in a relatively high learning curve for novices. Although SpringBoot reduces the configuration complexity and has convenient startup dependencies, due to the introduction of redundant libraries, it causes the application volume to expand and the startup time to extend. Especially in resource-constrained scenarios, the memory occupancy problem is more obvious. The performance of the embedded server in high-concurrency scenarios may be weaker than the optimized solution of independent deployment (such as the combination of Nginx + Tomcat), and the initialization steps of automatic configuration may slow down the startup speed. Additional optimization is required for scenarios with extremely high performance requirements.
[0004] For the above problems, the most ideal state is to set multiple network engines to handle different scenarios. During actual use, one of the already set network engines is specified for Spring Boot to use. However, in reality, if there are multiple network engines under Spring Boot at the same time, Spring Boot will automatically detect conflicts and report errors when the program starts, and at this time, the business program will not be able to start normally. In the prior art, there is, for example, the invention patent "An Exception Handling Method in a Hybrid Mode Execution Engine" with the patent number CN201110204556.9. This invention aims at the mixed working mode of multiple execution engines existing in the existing Java virtual machine, formulates corresponding exception handling strategies according to the different characteristics of different execution engines, and thus proposes a new type of exception handling method, including finding the first matching Catch block, obtaining the information of the Catch block and the function where the Catch block is located for a certain exception through function calls, changing the execution flow to this Catch block, and at the same time, the stack information also needs to be rolled back layer by layer to the stack frame corresponding to the function where this Catch block is located. This invention solves the exception handling problem in the Java virtual machine under multiple execution engines. However, this technology requires the use of virtual machine technology and can only handle exceptions after they occur, rather than actively preventing exceptions from occurring. In the prior art, there are also methods such as modifying and adjusting the pom.xml file or adjusting the JVM startup parameters to switch engines, but these means all require manual setting by technicians, and the setting parameters need to be adjusted for different engines and different application scenarios. The existing methods all have relatively high requirements for the capabilities of technicians. In addition, most of the existing engines are standards customized by foreign manufacturers. Now, domestic enterprises have also started to produce corresponding engines, but there will also be some problems with compatibility between the two, especially during the engine switching process, the probability of exceptions will increase. Summary of the Invention
[0005] Aiming at the shortcomings of the prior art, the purpose of the present invention is to solve the problem that multiple engines under the Spring Boot framework cannot adapt to different scenarios through automatic configuration.
[0006] To achieve this purpose, the present invention relates to a method for quickly switching the underlying network engine of a program based on the Spring Boot framework, including two separate types of projects: a running project and a packaging project. The running project includes a layout implementation class and a dynamic filtering rule engine; the packaging project includes a built-in layout factory and a class dynamic injection mechanism; the layout factory packages the business project into a customized class through a plugin based on the official main class layout; the packaging project is completed through a custom startup entry class, a custom Layout layout manager, and a customized ClassLoader, and the quick switching of the underlying network engine is completed by using the custom Layout layout manager.
[0007] Preferably, the custom startup entry class inherits JarLauncher and overrides the createClassLoader method to dynamically exclude dependent packages of non-target engines according to system parameters; different engine JAR packages are identified through a predefined dependency mapping table to achieve precise filtering. JarLauncher is a launcher class introduced in JavaSE 9 and later versions, which is used to optimize the startup method of JAR packages. It is part of the Java modular system and mainly solves the classpath management problem during the startup of traditional JAR packages. And createClassLoader refers to the method of creating a custom class loader (ClassLoader). The class loader is one of the core components of the JVM and is responsible for dynamically loading Java classes into memory.
[0008] Preferably, the content of the completed packaging project is compiled and pushed to the Maven private repository for subsequent projects to use. The Maven private repository refers to a private server built based on the Maven repository management specification, which is used to store JAR packages, plugins, and custom components depended on by projects. It is only open to internal teams and can store internal project components, third-party closed-source dependencies, or proxy caches of public repositories.
[0009] Preferably, a custom Layout layout manager is defined to extend JarLayout. During the packaging stage, the custom startup class is embedded into the final JAR package to ensure that the startup entry points to the custom logic. Combined with the Maven plugin configuration, the default packaging behavior is overridden to achieve layout logic injection. During the deployment stage, parameterized switching is performed without recompiling or pre-packaging multiple versions. The target engine is specified through startup parameters, and conflicting dependencies are automatically excluded.
[0010] Preferably, when customizing the ClassLoader, define the filtering packages, specifically by defining the static APPLICATION_SERVER_DEPENDENCIES in the relevant class and configuring the dependent package lists for different network engines respectively.
[0011] Preferably, when customizing the ClassLoader, methods also need to be overridden, specifically including: obtaining the network engine type from the startup parameter network.engine.type, counting the set of dependency package prefixes excludedJarNamePrefixs for non-specified network engines, traversing the URL array, comparing the jar package name with the prefix set, filtering out unnecessary URLs, and finally calling the parent class method to create the ClassLoader using the filtered URL array. By specifying the network.engine.type type in the startup parameter, dependency packages of other network engines can be excluded, achieving network engine switching. excludedJarNamePrefixs is a configuration parameter commonly found in Maven, Gradle, or custom build scripts for excluding JAR packages with specific prefixes.
[0012] Preferably, the network engines supported by Spring Boot include at least two of Tomcat, Jetty, Undertow, and Netty. Tomcat is an open-source project of the Apache Foundation, with an active community and an extremely rich ecosystem. Almost all JavaWeb frameworks are compatible with Tomcat.
[0013] Jetty is an open-source project maintained by the Eclipse Foundation and is well integrated with frameworks such as Spring and Quarkus. It is commonly used in scenarios that require asynchronous features.
[0014] Undertow is developed by RedHat and is the default container of the WildFly application server. It is deeply integrated with the OpenShift cloud platform, and its ecosystem depends on the RedHat technology stack.
[0015] Netty is also an open-source project maintained by JBoss and is the underlying foundation of many high-performance middleware. It is suitable for development teams with customization requirements.
[0016] Preferably, the network engines supported by Spring Boot also include TongWeb. TongWeb is an enterprise-level Java application server, which is a domestic middleware product mainly used to support the deployment and operation of enterprise-level Web applications. Its positioning is similar to Oracle WebLogic and IBM WebSphere. It supports the JavaEE (now JakartaEE) specification and provides a complete application container environment, including enterprise-level functions such as Servlet containers, EJB containers, JMS services, and transaction management.
[0017] The present invention also relates to an electronic device, including: A memory for storing a computer program; A processor, when executing a program stored in a memory, implements the method for quickly switching the underlying network engine of a program based on the Spring Boot framework.
[0018] The present invention also relates to a computer-readable storage medium, in which a computer program is stored, and when the computer program is executed by a processor, it implements the method for quickly switching the underlying network engine of a program based on the Spring Boot framework.
[0019] This solution splits the complete engineering process into two related stages: a running project and a packaging project. Through the separation of responsibilities in the development stage, plug-in customization in the packaging stage, and dynamic dependency management in the running stage, the maintainability, scalability, and flexibility of the system are ultimately improved. In particular, through dynamic dependency management at runtime, there is no need to pre-package multiple versions or modify the code, achieving zero-cost switching of the network engine, adapting to the rapid adaptation requirements of engines at home and abroad with certain differences, and avoiding the storage and maintenance overhead of multi-version packaging. Due to the adoption of the above technical solution, the present invention solves the problems of complexity and technical threshold of technical solutions such as modifying the pom document or manually mounting the dependency directory in the traditional solution, reduces the deployment risk, and greatly improves the flexibility and portability of the framework. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or in the prior art, the following will briefly introduce the drawings required for the description of the embodiments or the prior art. Obviously, the drawings in the following description are only some embodiments of the present invention.
[0021] Figure 1 It is: a schematic flowchart of the method for quickly switching the underlying network engine of a program based on the Spring Boot framework of the present invention; Figure 2 It is: a schematic flowchart of the main steps of the method for quickly switching the underlying network engine of a program based on the Spring Boot framework of the present invention to implement the embodiments of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0022] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the drawings in the embodiments of the present invention. It can be understood that the specific embodiments described herein are only used to explain the relevant content and are not a limitation to the present disclosure.
[0023] There are various network engines preset in the Spring Boot framework. However, in actual use, we must specify one of the network engines for Spring Boot to use. If there are multiple network engines existing simultaneously, Spring Boot will automatically detect conflicts and report errors when starting the program. At this time, the business program will not be able to start normally.
[0024] For example, based on the default Tomcat, without excluding the Tomcat network engine, we directly add the dependency of the Jetty network engine. The corresponding complete dependencies are as follows: <dependency> <groupid>org.springframework.boot< / groupid> <artifactid>spring-boot-starter-tomcat< / artifactid> < / dependency> <dependency> <groupid>org.springframework.boot< / groupid> <artifactid>spring-boot-starter-jetty< / artifactid> < / dependency> After starting, the error is as follows: 2025-03-10 13:47:37.163 ERROR 7060 o.s.boot.SpringApplication [main]: Application run failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name'serverEndpoint' defined in class path resource; Obviously, adding the dependency of the Jetty network engine in this way cannot be used normally.
[0025] To demonstrate the creativity of the present invention, the applicant compares it with the existing technical solutions. First, two sets of conventional solutions in the prior art are described: Prior art solution 1: Adjust the pom.xml file Some existing solutions are to explicitly modify the dependencies in the project's dependency declaration file pom.xml. When a new network engine needs to be used, manually remove the default Tomcat network engine dependency and add the new network engine dependency at the same time.
[0026] The example is as follows: <dependency> <groupid>org.springframework.boot< / groupid> <artifactid>spring-boot-starter-web< / artifactid> <exclusions> <exclusion> <groupid>org.springframework.boot< / groupid> <artifactid>spring-boot-starter-tomcat< / artifactid> < / exclusion> < / exclusions> < / dependency> <dependency> <groupid>org.springframework.boot< / groupid> <artifactid>spring-boot-starter-jetty< / artifactid> < / dependency> As can be seen from the above content, this method is to explicitly exclude the Tomcat network engine by the R & D personnel during the development stage, and at the same time introduce the declaration of the Jetty network engine. At this time, the network engine can be switched.
[0027] However, since it is impossible to predict in advance the specific network engine that customers will need to use during the deployment phase in the development stage, this solution can usually only be used for rework or modification when the initial engine is not satisfactory, and it is impossible to switch the network engine in real time during the deployment phase.
[0028] If corresponding packages are built for each network engine in advance during the development stage, the packaging cost and file storage cost will increase exponentially, which does not meet the business requirements.
[0029] Solution 2 in the prior art: Adjust JVM startup parameters Some other existing solutions adopt the method of excluding all network engine-related dependency packages in advance during packaging. At this time, the packaged package does not contain any network engine dependency packages. After releasing the program, the implementer specifies an additional dependency directory during the deployment phase at the customer site, and places the specific network engine dependency packages in this directory according to the actual needs of the customer. The example is as follows: java -Dloader.paths=libs -jar your-app.jar At this time, place the network engine dependency packages specified by the customer in the libs directory, and the goal can be achieved.
[0030] Although this can flexibly switch the network engine during the deployment phase, the problem is that the deployment personnel need to know the corresponding dependency package files according to the customer's needs, correctly find the dependency package files, upload and download files at the deployment site, and correctly edit the startup script. This requires extremely high technical capabilities of the deployment personnel, and the steps are numerous and very troublesome. Any mistake in any step will cause the entire program to fail to start, and the maintenance cost of the entire system is also very high.
[0031] Such as Figure 1As shown in the figure, in response to the problems existing in the prior art, the specific solution adopted by the present invention is as follows: Provide a method for quickly switching the underlying network engine of a program based on the Spring Boot framework, including two separate types of projects: a running project and a packaging project. The running project includes a layout implementation class and a dynamic filtering rule engine; the packaging project includes a built-in layout factory and a class dynamic injection mechanism; the layout factory packages the business project into customized classes through plugins based on the official main class layout; the packaging project is completed by customizing the startup entry class, customizing the Layout layout manager, and customizing the ClassLoader, and the quick switching of the underlying network engine is completed by using the custom Layout layout manager. When customizing the ClassLoader, filter packages are defined, and static APPLICATION_SERVER_DEPENDENCIES are defined in relevant classes, and dependency package lists of different network engines are configured respectively. When customizing the ClassLoader, methods also need to be rewritten, specifically including: obtaining the network engine type from the startup parameter network.engine.type, counting the set of dependency package prefixes excludedJarNamePrefixs of non-specified network engines, traversing the URL array, comparing the jar package name with the prefix set, filtering out unnecessary URLs, and finally using the filtered URL array to call the parent class method to create the ClassLoader. The content of the completed packaging project is compiled and pushed to the Maven private repository for subsequent projects to use. The custom startup entry class inherits JarLauncher and overrides the createClassLoader method to dynamically exclude the dependency packages of non-target engines according to system parameters; the JAR packages of different engines are identified through a predefined dependency mapping table. Customize the Layout layout manager, extend JarLayout, embed the custom startup class into the final JAR package during the packaging phase to ensure that the startup entry points to the custom logic, combine with the Maven plugin configuration to override the default packaging behavior, implement layout logic injection, and perform parameterized switching during the deployment phase. Specify the target engine through the startup parameter to automatically exclude conflicting dependencies.
[0032] The network engines supported by Spring Boot include at least two of Tomcat, Jetty, Undertow, and Netty, and also include TongWeb.
[0033] Here, it is necessary to explain the relevant terms: Running project: Responsible for the actual running logic of the application, including two core components: a layout implementation class and a dynamic filtering rule engine.
[0034] Layout implementation class: Defines the overall structure and component relationships of the application, such as page layout, and the interaction method between the service layer and the data layer.
[0035] Dynamic filtering rule engine: Dynamically filter or exclude specific dependencies at runtime, for example, decide whether to load the network engine classes of Tomcat or TongWeb according to startup parameters.
[0036] Packaging project: Focus on the construction and packaging process of the application, including: built-in layout factory and class dynamic injection mechanism.
[0037] Among them, the built-in layout factory: Based on the official main class layout of Spring, convert the business project into a customized class structure through plugins to ensure that the packaged application meets specific deployment requirements.
[0038] Class dynamic injection mechanism: Inject custom components, such as startup classes and layout managers, into the final JAR package during the packaging stage to replace the default implementation.
[0039] The official main class layout refers to the default application startup structure of Spring Boot, with the main class annotated with @SpringBootApplication as the entry point, and start the application context through the SpringApplication.run() method. Based on this, the layout factory realizes customized packaging by extending or modifying its behavior.
[0040] Custom Layout layout manager: Extend the JarLayout, the default layout strategy of Spring Boot, to embed custom startup classes or modify the packaging structure and support parameterized switching during the packaging stage.
[0041] Embed custom startup class: Embed the custom startup entry class into META-INF / MANIFEST.MF of the final JAR package to override the default startup logic.
[0042] Modify the packaging structure: Adjust the directory organization inside the JAR package to ensure that dependencies are loaded as expected.
[0043] Parameterized switching: Through the configuration of Maven plugins, the layout logic can be dynamically adjusted through startup parameters during the deployment stage.
[0044] Custom ClassLoader, the ClassLoader is a custom class loader that realizes dependency filtering through a static dependency list and URL filtering.
[0045] Static dependency list: Predefine the dependency package names of different network engines through the APPLICATION_SERVER_DEPENDENCIES constant, such as servlet-api.jar for Tomcat and tongweb.jar for TongWeb.
[0046] APPLICATION_SERVER_DEPENDENCIES; Static constant that stores a list of dependency package names for different application server network engines.
[0047] URL Filtering: When overriding the createClassLoader() method, traverse all URLs to be loaded, exclude the dependency package prefixes of non-target engines, and ensure that only classes of the specified engine are loaded.
[0048] Custom Startup Entry Class: In the Spring Boot framework, the JarLauncher class is used as the startup entry for the executable JAR by default. The custom startup entry class inherits from JarLauncher and overrides its core methods to achieve precise control over the class loading process. Therefore, the custom startup entry class described in this invention inherits from JarLauncher and overrides the createClassLoader method to dynamically exclude the dependency packages of non-target engines based on system parameters; identify the JAR packages of different engines through a predefined dependency mapping table to achieve precise filtering.
[0049] After compiling the content of the packaging project, push it to the Maven private repository for subsequent projects to use. The Maven private repository is the Maven repository server within the enterprise, which stores the compiled custom JAR packages. By pushing the packaging project to the private repository, other projects can directly reference this package to achieve a quick switch of the underlying network engine without repeated compilation.
[0050] As Figure 2 shown below, the following specific embodiments are used to illustrate the technical solutions adopted by this invention: In this embodiment, the business project needs to switch to any one of the two network engines, tomcat / TongWeb of Tongtech, at any time to provide services externally, and quickly and flexibly switch the network engine during the deployment phase.
[0051] Step 1: Custom Startup Entry Class: Create a new project jar-launch, and then create a class public class MyJarLauncher extends JarLauncher { / / Key function public static void main(String[] args) throws Exception { new MyJarLauncher().launch(args); } } Step 2: Customize the Layout Manager: public class MyJarLayout extends Jar implements CustomLoaderLayout { @Override public void writeLoadedClasses(LoaderClassesWriter w) throws Exception { / / Key code writer.writeLoaderClasses("META-INF / loader / jar-launch.jar"); } / / Launch class @Override public String getLauncherClassName() { return MyJarLauncher class path; } } The specific content of MyLayoutFactory.java is as follows: public class MyLayoutFactory extends DefaultLayoutFactory { @Override public Layout getLayout(File source) { String lowerCaseFileName = source.getName().toLowerCase(Locale.ENGLISH); if (lowerCaseFileName.endsWith(".jar")) { return new MyJarLayout(); } return super.getLayout(source); } } The project is compiled and pushed to the maven private repository for subsequent use.
[0052] Step 3: The business project uses a custom Layout layout manager: The business objective in this step is to adjust the behavior of the maven packaging plugin in any business project that needs to quickly switch network engines, specifically as follows: <plugin> <groupid>org.springframework.boot< / groupid> <artifactid>spring-boot-maven-plugin< / artifactid> <executions> <execution> <id>repackage< / id> <goals> <goal>repackage< / goal> < / goals> <configuration> <layoutfactory implementation="com.fingard.rdc.avatar.cd.MyLayoutFactory" / > < / configuration> < / execution> < / executions> < / plugin> By using the MyLayoutFactory class in the repackage phase of packaging, according to the above description, a custom layout implementation class MyJarLayout object is returned, which mainly implements the following two behaviors: 1) Write the classes related to the jar-launch project into the final jar package 2) Modify the name of the startup class At this point, the final executable package will start execution from our custom startup class, successfully implementing the replacement of the startup class entry.
[0053] Step 4: Customize the ClassLoader: Based on the fact that the business project in this embodiment needs to switch to any one of the two network engines, tomcat / TongWeb of Tongfang, to provide services externally at any time, the following will explain how to define the ClassLoader to achieve this.
[0054] / / Filter packages private static final Map<String, String[]> APPLICATION_SERVER_DEPENDENCIES = new ConcurrentHashMap<String, String[]>(); static { / / Dependencies of tomcat APPLICATION_SERVER_DEPENDENCIES.put("tomcat", new String[] { "tomcat-embed-core", "tomcat-embed-el", "tomcat-embed-websocket", "spring-boot-starter-tomcat" }); / / Dependencies of TongWeb of Tongfang APPLICATION_SERVER_DEPENDENCIES.put("tongweb", new String[] { "tongweb-dependencies-check", "tongweb-embed-core", "tongweb-embed-el", }); } @Override protected ClassLoader createClassLoader(URL[] urls) throws Exception{ / / According to the network engine type -> count the dependent packages of other network engines that need to be excluded String engine = System.getProperty("network.engine.type", "tomcat"); Set <string>excludedJarNamePrefixs = new HashSet <string>(); for (Entry<String, String[]> entry : APPLICATION_SERVER_DEPENDENCIES.entrySet()) { if (!entry.getKey().equalsIgnoreCase(engine)) { excludedJarNamePrefixs.addAll(Arrays.asList(entry.getValue())); } } List <url>filteredUrlList = new ArrayList<>(); / / Traverse the current URL for (final URL url : urls) { String path = url.getPath(); / / Name normalization if (path.endsWith(".jar! / ")) { path = path.substring(0, path.length() - 2); } / / Keep directly if not.jar if (!path.endsWith(".jar")) { filteredUrlList.add(url); continue; } / / Compare according to the jar name String jarName = path.substring(path.lastIndexOf(' / ') + 1); if (excludedJarNamePrefixs.stream().noneMatch(jarName::startsWith)) { / / Need to keep filteredUrlList.add(url); } else { / / Need to discard System.out.println("Discard ->" + url); } } return super.createClassLoader(filteredUrlList.toArray(new URL[0])); } By specifying the type of network.engine.type in the startup parameters, other network engine dependencies can be excluded, thus achieving the switching of the underlying network engine.
[0055] It can be seen that the core of implementing dynamic switching of the underlying network engine based on the SpringBoot framework in the present invention lies in customizing the startup entry class to inherit JarLauncher and rewrite the createClassLoader method, combining with the predefined APPLICATION_SERVER_DEPENDENCIES dependency mapping table, and dynamically filtering the dependency packages of non-target engines according to the startup parameters; at the same time, by customizing the Layout layout manager to extend JarLayout, embedding the custom startup class into the JAR package and modifying the MANIFEST.MF startup entry during the packaging stage, and combining with the Maven plug-in configuration to implement layout logic injection; during deployment, only the target engine type needs to be specified through the startup parameters, and the ClassLoader will automatically traverse the URL array and filter out conflicting dependencies according to the dependency prefix, so as to achieve seamless switching of multiple engines such as Tomcat and TongWeb. This solution realizes flexible switching of the engine during the deployment stage through the class loading control and dependency dynamic filtering mechanism, and has the advantages of compatibility, reusability and low maintenance cost without modifying the business code.
[0056] The following table shows the comparison of the response time adopted in the present invention and the corresponding direction in the prior art:
[0057] It should be noted that although the unit is seconds, in the financial service industry, the impact caused by a difference of several seconds is very huge.
[0058] In addition, the present invention further includes an electronic device, including: A memory for storing a computer program; A processor, when executing the program stored on the memory, realizes the method for quickly switching the underlying network engine of the program based on the SpringBoot framework.
[0059] The present invention further includes a computer-readable storage medium, in which a computer program is stored, and when the computer program is executed by a processor, the method for quickly switching the underlying network engine of the program based on the SpringBoot framework is realized.
[0060] Although the present invention is disclosed above in preferred embodiments, it is not intended to limit the scope of the present invention. Any person of ordinary skill in the art can make some improvements without departing from the scope of the present invention. That is, any equivalent improvements made in accordance with the present invention should be covered by the scope of the present invention. In the description of this specification, the description of reference terms such as "one embodiment / way", "some embodiments / ways", "example", "specific example", or "some examples" means that the specific features, structures, materials, or characteristics described in connection with the embodiment / way or example are included in at least one embodiment / way or example of this application. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment / way or example. Moreover, the specific features, structures, materials, or characteristics described can be combined in a suitable manner in any one or more embodiments / ways or examples. In addition, without contradiction, those skilled in the art can combine and combine the different embodiments / ways or examples described in this specification and the features of different embodiments / ways or examples.
[0061] In addition, the terms "first" and "second" are used for descriptive purposes only and cannot be construed as indicating or implying relative importance or implicitly indicating the quantity of the indicated technical features. Thus, the features defined with "first" and "second" may explicitly or implicitly include at least one of these features. In the description of this application, "a plurality" means at least two, such as two, three, etc., unless otherwise specifically defined.
[0062] Those skilled in the art should understand that the above embodiments are only for clearly explaining the present disclosure and not for limiting the scope of the present disclosure. For those skilled in the art, other changes or modifications can be made on the basis of the above disclosure, and these changes or modifications are still within the scope of the present disclosure.< / url> < / string> < / string>
Claims
1. Method for quickly switching the underlying network engine of a program based on the Spring Boot framework, characterized in that It includes two separate types of projects: the running project and the packaging project. The running project contains a layout implementation class and a dynamic filtering rule engine; the packaging project includes a built-in layout factory and a class dynamic injection mechanism; The layout factory packages the business project into a customized class through a plugin based on the official main class layout; the packaging project is completed by customizing the startup entry class, the custom Layout layout manager, and the customized ClassLoader, and the underlying network engine is quickly switched by using the custom Layout layout manager.
2. The method for quickly switching the underlying network engine of a program based on the SpringBoot framework according to claim 1, characterized in that, The custom startup entry class inherits JarLauncher and overrides the createClassLoader method to dynamically exclude the dependency packages of non-target engines according to system parameters; different engine JAR packages are identified through a predefined dependency mapping table.
3. The method for quickly switching the underlying network engine of a program based on the SpringBoot framework according to claim 2, wherein The content of the completed packaging project is compiled and pushed to the Maven private repository for subsequent projects to use.
4. The method for quickly switching the underlying network engine of a program based on the Spring Boot framework according to claim 1, wherein The custom Layout layout manager extends JarLayout, embeds the custom startup class into the final JAR package during the packaging stage to ensure that the startup entry points to the custom logic. Combined with the Maven plugin configuration, it overrides the default packaging behavior to achieve layout logic injection. During the deployment stage, parameterized switching is performed, and the target engine is specified through startup parameters to automatically exclude conflicting dependencies.
5. The method for quickly switching the underlying network engine of a program based on the SpringBoot framework according to claim 1, characterized in that Define the filtered packages when customizing the ClassLoader. Specifically, define the static APPLICATION_SERVER_DEPENDENCIES in the relevant classes and configure the dependency package lists of different network engines respectively.
6. The method for quickly switching the underlying network engine of a program based on the SpringBoot framework according to claim 1, characterized in that, When customizing the ClassLoader, methods also need to be overridden. Specifically, it includes: obtaining the network engine type from the startup parameter network.engine.type, counting the set of dependency package prefixes excludedJarNamePrefixs of non-specified network engines, traversing the URL array, comparing the jar package name with the prefix set, filtering out the unnecessary URLs, and finally using the filtered URL array to call the parent class method to create the ClassLoader.
7. The method for quickly switching the underlying network engine of a program based on the Spring Boot framework according to any one of claims 1-6, characterized in that, The network engines supported by Spring Boot include at least two of Tomcat, Jetty, Undertow, and Netty.
8. The method for quickly switching the underlying network engine of a program based on the Spring Boot framework according to any one of claims 1-6, characterized in that, The network engines supported by Spring Boot also include TongWeb.
9. An electronic device, characterized in that, It includes: A memory for storing computer programs; A processor for implementing the method according to any one of claims 1-8 when executing the program stored on the memory.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, and when the computer program is executed by the processor, the method according to any one of claims 1-8 is implemented.
Citation Information
Patent Citations
Low-coupling extended business system based on plug-in engine injection
CN112363755A
Integrated unit testing method and system based on SpringBoot
CN114416536A
Dependence management and tool integration method based on springboot
CN115712456A
Coupling data network cloud information management and control platform based on numerical physical simulation
CN117252006A
Methods, systems, and articles of manufacture for implementing physical designs with force directed placement or floorplanning and layout decomposition
US9098667B1