A method for quickly switching a program underlying network engine based on a SpringBoot framework

By separating the running and packaging projects in the SpringBoot framework, customizing the startup entry and ClassLoader, and combining Maven private service and plug-in configuration, we can achieve fast and seamless switching of the underlying network engine, solve the problem of multi-engine conflicts, and improve the flexibility and maintainability of the system.

CN120406920BActive Publication Date: 2025-10-10ZHEJIANG FINGARD TECH CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202510928561.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-07-07
Publication Date
2025-10-10
Estimated Expiration
2045-07-07

AI Technical Summary

Technical Problem

The multiple engines under the SpringBoot framework cannot adapt to different scenarios through automatic configuration, resulting in program startup conflicts. In addition, the existing technical solutions require high technical capabilities, and the deployment is complex and costly.

Method used

By adopting separate running projects and packaging projects, and through customized startup entry classes, customized Layout layout managers and customized ClassLoader, we can achieve fast switching of the underlying network engine, including customized layout factories and class dynamic injection mechanisms, dynamic filtering rule engines, combined with Maven private servers and Maven plug-in configurations, to achieve seamless engine switching.

Benefits of technology

It enables flexible switching of network engines during the deployment phase, lowers the technical threshold, improves the maintainability and flexibility of the system, meets the rapid adaptation needs of domestic and foreign engines, and avoids the storage and maintenance costs of multi-version packaging.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120406920B_ABST
    Figure CN120406920B_ABST
Patent Text Reader

Abstract

The application belongs to the technical field of computer software, and aims to solve the problem that multiple engines under a SpringBoot framework cannot adapt to different scenes through automatic configuration. To this end, the application provides a method for quickly switching the underlying network engine of a program based on a SpringBoot framework, which comprises a separated running project and a packaged project. The packaged project is completed through customizing a startup entry class, customizing a Layout layout manager, and customizing a ClassLoader. The quick switching of the underlying network engine is completed through using the custom Layout layout manager. The scheme realizes the zero-cost switching of the network engine through runtime dynamic dependency management, without the need of pre-packaging multiple versions or modifying codes, and adapts to the quick adaptation requirements of domestic and foreign engines with certain differences, thereby avoiding the storage and maintenance overhead of multiple versions of packaging.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of computer software, and in particular to a method for quickly switching a program's underlying network engine. Background Art

[0002] Spring Boot is an open-source Java development framework based on the Spring Framework. It aims to simplify the initial setup and development 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-grade applications.

[0003] However, the "black box" nature of its automatic configuration makes debugging difficult. Developers need a deep understanding of the underlying mechanisms to address customized requirements, resulting in a high learning curve for novices. Although Spring Boot reduces configuration complexity and facilitates easy startup, the introduction of redundant libraries leads to application size expansion and prolonged startup time. Memory usage is particularly problematic in resource-constrained scenarios. The performance of the embedded server in high-concurrency scenarios may be weaker than that of optimized standalone deployments (such as the Nginx + Tomcat combination), and the automatic configuration initialization steps may slow startup. Scenarios with extreme performance requirements require additional optimization.

[0004] To address the above issues, the ideal solution is to set up multiple network engines to handle different scenarios. In practice, one of the pre-set network engines is designated for SpringBoot. However, in reality, if multiple network engines coexist under SpringBoot, the SpringBoot program will automatically detect a conflict upon startup and report an error, preventing the business program from starting properly. Prior art patents include invention patent number CN201110204556.9, "An Exception Handling Method Operating in a Mixed-Mode Execution Engine." This invention addresses the mixed-mode operation of multiple execution engines in existing Java virtual machines by developing corresponding exception handling strategies based on the varying characteristics of each execution engine. This method proposes a novel exception handling method, which involves finding the first matching catch block, obtaining information about the catch block and the function containing the catch block through a function call, and then redirecting the execution flow to this catch block. Furthermore, stack information is rolled back layer by layer to the stack frame corresponding to the function containing the catch block. This invention addresses the exception handling problem in Java virtual machines operating under multiple execution engines. However, this technology requires the use of virtual machine technology, and it waits until an exception occurs before processing, rather than proactively preventing the occurrence of an exception. There are also existing methods in the art, such as modifying and adjusting the pom.xml file, or adjusting the JVM startup parameters to switch engines, but these methods require manual settings by technicians, and the setting parameters need to be adjusted for different engines and different application scenarios. The existing methods all have high requirements on the ability of technicians. In addition, most engines in the existing art are customized standards by foreign manufacturers. Now domestic companies have also begun to produce corresponding engines, but there are also some compatibility issues between the two. In particular, the probability of anomalies will increase during the engine switching process. Summary of the Invention

[0005] In view of the shortcomings of the prior art, the purpose of the present invention is to solve the problem that multiple engines under the SpringBoot framework cannot adapt to different scenarios through automatic configuration.

[0006] To achieve this object, the present invention relates to a method for quickly switching the underlying network engine of a program based on a SpringBoot framework, comprising 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 plug-in based on the official main class layout; the packaging project is completed through a customized startup entry class, a customized Layout layout manager, and a customized ClassLoader, and the rapid switching of the underlying network engine is achieved by using the customized Layout layout manager.

[0007] Preferably, the custom startup entry class inherits JarLauncher and overrides the createClassLoader method to dynamically exclude dependency packages of non-target engines based on system parameters; JAR packages of different engines are identified through a predefined dependency mapping table to achieve precise filtering. JarLauncher is a launcher class introduced in JavaSE9 and higher versions, which is used to optimize the startup method of JAR packages. It is part of the Java modular system and mainly solves the class path management problem when traditional JAR packages are started. 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 completed packaged project content is compiled and pushed to a Maven private server for use in subsequent projects. A Maven private server is a private server built based on the Maven repository management specification, used to store project dependency JARs, plugins, and custom artifacts. It is only accessible to internal teams and can store internal project artifacts, third-party closed-source dependencies, or serve as a proxy cache for public repositories.

[0009] Preferably, a custom Layout layout manager is used to extend JarLayout. The custom startup class is embedded in the final JAR package during the packaging phase to ensure that the startup entry points to the custom logic. Combined with the Maven plug-in configuration, the default packaging behavior is overwritten to implement layout logic injection. Parameterized switching is performed during the deployment phase without the need to recompile or pre-package multiple versions. The target engine is specified through startup parameters to automatically eliminate conflicting dependencies.

[0010] Preferably, when customizing ClassLoader, a filter package is defined, specifically by defining a static APPLICATION_SERVER_DEPENDENCIES in the relevant class, and configuring dependency package lists for different network engines respectively.

[0011] Preferably, when customizing ClassLoader, it is also necessary to rewrite the method, specifically including: obtaining the network engine type from the startup parameter network.engine.type, counting the dependency package prefix set excludedJarNamePrefixs of non-specified network engines, traversing the URL array, filtering out unnecessary URLs based on the comparison of the jar package name with the prefix set, and finally using the filtered URL array to call the parent class method to create ClassLoader. By specifying the network.engine.type type in the startup parameters, other network engine dependency packages can be excluded to achieve network engine switching. excludedJarNamePrefixs is a common configuration parameter in Maven, Gradle or custom build scripts, which is used to exclude JAR packages with specific prefixes.

[0012] Preferably, the network engines supported by SpringBoot 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 a rich ecosystem. Almost all Java Web frameworks are compatible with Tomcat.

[0013] Jetty is an open source project maintained by the Eclipse Foundation. It integrates well with frameworks such as Spring and Quarkus and is often used in scenarios that require asynchronous features.

[0014] Developed by Red Hat, Undertow is the default container for the WildFly application server. It is deeply integrated with the OpenShift cloud platform and its ecosystem relies on the Red Hat technology stack.

[0015] Netty is also an open source project maintained by JBoss. It is the underlying foundation of many high-performance middleware and is suitable for development teams with customized needs.

[0016] Preferably, the network engine supported by Spring Boot also includes TongWeb. TongWeb is an enterprise-level Java application server and a domestically produced middleware product, primarily used to support the deployment and operation of enterprise-level web applications. Its positioning is similar to that of Oracle WebLogic and IBM WebSphere, supporting Java EE (now Jakarta EE) specifications and providing a complete application container environment, including Servlet containers, EJB containers, JMS services, transaction management, and other enterprise-level features.

[0017] The present invention also relates to an electronic device, comprising:

[0018] Memory for storing computer programs;

[0019] The processor is used to implement the method of quickly switching the underlying network engine of the program based on the SpringBoot framework when executing the program stored in the memory.

[0020] The present invention also relates to a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, a method for quickly switching the underlying network engine of the program based on the SpringBoot framework is implemented.

[0021] This solution splits the complete engineering process into two related stages: the running project and the packaging project. Through the separation of responsibilities in the development stage, the plug-in customization in the packaging stage, and the 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, which realizes zero-cost switching of network engines, adapts to the rapid adaptation needs of domestic and foreign engines with certain differences, and avoids the storage and maintenance overhead of multi-version packaging. Due to the adoption of the above-mentioned technical solution, the present invention solves the problems of complexity and technical threshold of technical solutions such as modifying pom documents or manually mounting dependency directories in traditional solutions, reduces deployment risks, and greatly improves the flexibility and portability of the framework. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present invention.

[0023] 图1 The present invention is a flowchart of a method for quickly switching the underlying network engine of a program based on the SpringBoot framework;

[0024] 图2 The present invention is a flowchart of the main steps of an embodiment of the present invention in a method for quickly switching the underlying network engine of a program based on the SpringBoot framework. DETAILED DESCRIPTION

[0025] The following will be combined with the accompanying drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. It should be understood that the specific implementation methods described here are only used to explain the relevant content, rather than to limit the present disclosure.

[0026] There are various network engines preset in the SpringBoot framework, but in actual use, we must specify one of the network engines for SpringBoot to use. If multiple network engines exist at the same time, the SpringBoot program will automatically detect conflicts and report errors when it starts, and the business program will not be able to start normally.

[0027] For example, based on the default Tomcat, we do not exclude the Tomcat network engine from directly adding the dependency of the Jetty network engine. The corresponding complete dependencies are as follows:

[0028] <dependency>

[0029] <groupid> org.springframework.boot < / groupid>

[0030] <artifactid> spring-boot-starter-tomcat < / artifactid>

[0031] < / dependency>

[0032] <dependency>

[0033] <groupid> org.springframework.boot < / groupid>

[0034] <artifactid> spring-boot-starter-jetty < / artifactid>

[0035] < / dependency>

[0036] After startup, the error is as follows:

[0037] 2025-03-10 13:47:37.163

[0038] ERROR 7060 osboot.SpringApplication

[0039] [main]: Application run failed

[0040] org.springframework.beans.factory.BeanCreationException: Errorcreating bean with name 'serverEndpoint' defined in class path resource;

[0041] Obviously, adding the dependency on the Jetty network engine will not work properly.

[0042] To demonstrate the creativity of the present invention, the applicant compares it with existing technical solutions in the prior art. First, two conventional solutions in the prior art are described:

[0043] Existing technical solution 1: Adjust the pom.xml file

[0044] 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.

[0045] Here is an example:

[0046] <dependency>

[0047] <groupid> org.springframework.boot < / groupid>

[0048] <artifactid> spring-boot-starter-web < / artifactid>

[0049] <exclusions>

[0050] <exclusion>

[0051] <groupid> org.springframework.boot < / groupid>

[0052] <artifactid> spring-boot-starter-tomcat < / artifactid>

[0053] < / exclusion>

[0054] < / exclusions>

[0055] < / dependency>

[0056] <dependency>

[0057] <groupid> org.springframework.boot < / groupid>

[0058] <artifactid> spring-boot-starter-jetty < / artifactid>

[0059] < / dependency>

[0060] From the above content, we can see that this method is achieved by R&D personnel explicitly excluding the Tomcat network engine during the development phase and introducing the Jetty network engine declaration, at which time the network engine can be switched.

[0061] However, since it is impossible to predict in advance during the development phase the specific network engine that the customer will need to use during the deployment phase, 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.

[0062] If a corresponding package is created for each network engine in advance during the development phase, the packaging cost and file storage cost will increase exponentially, which does not meet business needs.

[0063] Solution 2 in the prior art: Adjusting JVM startup parameters

[0064] Some other existing solutions exclude all network engine-related dependency packages in advance during packaging. The packaged package does not contain any network engine dependency packages. The program is released, and then the implementation personnel specify an additional dependency directory with the help of JVM startup parameters during the customer site deployment phase. In this directory, specific network engine dependency packages are placed according to the customer's actual needs. An example is as follows:

[0065] java -Dloader.paths=libs -jar your-app.jar

[0066] At this time, placing the customer-specified network engine dependency package in the libs directory can achieve the goal.

[0067] Although this method can flexibly switch network engines during the deployment phase, the problem it brings is that the deployment personnel must be able to know the corresponding dependency package files according to customer 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 many and very cumbersome. Any error in any step will cause the entire program startup to fail, and the maintenance cost of the entire system is also very high.

[0068] like 图1 As shown, to address the problems existing in the prior art, the present invention adopts a specific solution: providing a method for quickly switching the underlying network engine of a program based on the SpringBoot framework, comprising two separate 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 plug-in based on the official main class layout; the packaging project is completed through a customized startup entry class, a customized Layout layout manager, and a customized ClassLoader, and the customized Layout layout manager is used to achieve rapid switching of the underlying network engine. When customizing the ClassLoader, a filter package is defined, and the static APPLICATION_SERVER_DEPENDENCIES is defined in the relevant class to configure the dependency package list of different network engines. When customizing the ClassLoader, a method rewriting is also required, specifically including: obtaining the network engine type from the startup parameter network.engine.type; counting the dependency package prefix set excludedJarNamePrefixs of non-specified network engines; iterating through 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. After the contents of the completed packaging project are compiled, they are pushed to the Maven private server for use in subsequent projects. The custom startup entry class inherits JarLauncher and overrides the createClassLoader method to dynamically exclude dependency packages of non-target engines based on system parameters; JAR packages of different engines are identified through predefined dependency mapping tables. Customize the Layout layout manager, extend JarLayout, embed the custom startup class into the final JAR package during the packaging phase, ensure that the startup entry points to the custom logic, combine with Maven plug-in configuration, override the default packaging behavior, implement layout logic injection, perform parameterized switching during the deployment phase, specify the target engine through startup parameters, and automatically exclude conflicting dependencies.

[0069] The network engines supported by SpringBoot include: at least two of Tomcat, Jetty, Undertow, Netty, and TongWeb.

[0070] Here we need to explain the relevant terms:

[0071] Operation project: responsible for the actual operation logic of the application, including two core components: layout implementation class and dynamic filtering rule engine.

[0072] Layout implementation class: defines the overall structure and component relationships of the application, such as page layout and the interaction between the service layer and the data layer.

[0073] Dynamic filtering rule engine: Dynamically filters or excludes specific dependencies based on conditions at runtime, such as deciding whether to load Tomcat or TongWeb's network engine class based on startup parameters.

[0074] Packaging project: focuses on the application construction and packaging process, including: built-in layout factory and class dynamic injection mechanism.

[0075] The built-in layout factory: based on the official Spring main class layout, it converts business projects into customized class structures through plug-ins to ensure that the packaged application meets specific deployment requirements.

[0076] Dynamic class injection mechanism: Inject custom components, such as startup classes and layout managers, into the final JAR package during the packaging phase to replace the default implementation.

[0077] The official main class layout refers to the default application startup structure of Spring Boot, which uses the main class annotated with @SpringBootApplication as the entry point and starts the application context through the SpringApplication.run() method. Layout factories use this as a basis and implement customized packaging by extending or modifying its behavior.

[0078] Custom Layout layout manager: Extends JarLayout, the SpringBoot default layout strategy, to embed custom startup classes, modify packaging structures, and support parameterized switching during the packaging phase.

[0079] Embed a custom startup class: Embed the custom startup entry class into the META-INF / MANIFEST.MF of the final JAR package to overwrite the default startup logic.

[0080] Modify the packaging structure: Adjust the directory organization inside the JAR package to ensure that dependencies are loaded as expected.

[0081] Parameterized switching: Through Maven plug-in configuration, the layout logic can be dynamically adjusted through startup parameters during the deployment phase.

[0082] Custom ClassLoader, ClassLoader is a custom class loader that implements dependency filtering through static dependency lists and URL filtering.

[0083] Static dependency list: Use the APPLICATION_SERVER_DEPENDENCIES constant to predefine the dependency package names of different network engines, such as Tomcat's servlet-api.jar and TongWeb's tongweb.jar.

[0084] APPLICATION_SERVER_DEPENDENCIES; static constant, stores the list of dependent package names of different application server network engines.

[0085] 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.

[0086] Custom startup entry class: In the SpringBoot framework, the JarLauncher class is used by default as the startup entry point for executable JARs. By inheriting JarLauncher and overriding its core methods, the custom startup entry class achieves precise control over the class loading process. Therefore, the custom startup entry class described in this invention inherits JarLauncher and overrides the createClassLoader method, dynamically excluding dependencies of non-target engines based on system parameters. JAR packages for different engines are identified through a predefined dependency mapping table, enabling precise filtering.

[0087] After compiling the packaged project, push it to a private Maven server for use in subsequent projects. A private Maven server is an internal Maven repository server that stores compiled custom JAR files. By pushing the packaged project to a private server, other projects can directly reference the package, enabling quick switching of underlying network engines without requiring repeated compilation.

[0088] like 图2 As shown, the technical solution adopted by the present invention is illustrated below with a specific embodiment: In this embodiment, the business project needs to switch to any of the two network engines, tomcat / Eastern Tongtongweb, at any time to provide services to the outside world, and quickly and flexibly switch the network engine during the deployment phase.

[0089] Step 1: Customize the startup entry class:

[0090] Create a new project jar-launch, then create a new class

[0091] public class MyJarLauncher extends JarLauncher {

[0092] / / Key functions

[0093] public static void main(String[] args) throws Exception {

[0094] new MyJarLauncher().launch(args);

[0095] }

[0096] }

[0097] Step 2: Customize the Layout manager:

[0098] public class MyJarLayout extends Jar implements CustomLoaderLayout {

[0099] @Override

[0100] public void writeLoadedClasses(LoaderClassesWriter w) throwsException {

[0101] / / Key code

[0102] writer.writeLoaderClasses("META-INF / loader / jar-launch.jar");

[0103] }

[0104] / / Startup class

[0105] @Override

[0106] public String getLauncherClassName() {

[0107] return MyJarLauncher classpath;

[0108] }

[0109] }

[0110] The specific content of MyLayoutFactory.java is:

[0111] public class MyLayoutFactory extends DefaultLayoutFactory {

[0112] @Override

[0113] public Layout getLayout(File source) {

[0114] String lowerCaseFileName = source.getName().toLowerCase(Locale.ENGLISH);

[0115] if (lowerCaseFileName.endsWith(".jar")) {

[0116] return new MyJarLayout();

[0117] }

[0118] return super.getLayout(source);

[0119] }

[0120] }

[0121] The project is compiled and pushed to the Maven private server for subsequent use.

[0122] Step 3: Use a custom Layout manager in the business project:

[0123] The business goal of this step is to adjust the behavior of the Maven packaging plugin in any business project that requires rapid switching of network engines. The details are as follows:

[0124] <plugin>

[0125] <groupid> org.springframework.boot < / groupid>

[0126] <artifactid> spring-boot-maven-plugin < / artifactid>

[0127] <executions>

[0128] <execution>

[0129] <id> repackage < / id>

[0130] <goals>

[0131] <goal> repackage< / goal>

[0132] < / goals>

[0133] <configuration>

[0134] <layoutfactory implementation="com.fingard.rdc.avatar.cd.MyLayoutFactory" / >

[0135] < / configuration>

[0136] < / execution>

[0137] < / executions>

[0138] < / plugin>

[0139] By using the MyLayoutFactory class in the repackage phase, according to the above description, a custom layout implementation class MyJarLayout object is returned. This object mainly implements the following two behaviors:

[0140] 1) Write the jar-launch project related classes into the final jar package

[0141] 2) Modify the name of the startup class

[0142] At this point, the final executable package will start executing from our customized startup class, successfully replacing the startup class entry.

[0143] Step 4: Customize ClassLoader:

[0144] In this embodiment, the business project needs to switch to any of the two network engines, tomcat and tongweb, to provide external services at any time. Next, we will explain how to define ClassLoader to achieve this.

[0145] / / Filter packets

[0146] private static final Map<String, String[]> APPLICATION_SERVER_DEPENDENCIES = new ConcurrentHashMap<String, String[]> ();

[0147] static {

[0148] / / Tomcat's dependencies

[0149] APPLICATION_SERVER_DEPENDENCIES.put("tomcat", new String[] {

[0150] "tomcat-embed-core",

[0151] "tomcat-embed-el",

[0152] "tomcat-embed-websocket",

[0153] "spring-boot-starter-tomcat"

[0154] });

[0155] / / Dependence of TongWeb

[0156] APPLICATION_SERVER_DEPENDENCIES.put("tongweb",

[0157] new String[] {

[0158] "tongweb-dependencies-check",

[0159] "tongweb-embed-core",

[0160] "tongweb-embed-el",

[0161] });

[0162] }

[0163] @Override

[0164] protected ClassLoader createClassLoader(URL[] urls) throws Exception{

[0165] / / According to the network engine type->Count the dependent packages of other network engines that need to be excluded

[0166] String engine = System.getProperty("network.engine.type", "tomcat");

[0167] Set <string>excludedJarNamePrefixs = new HashSet <string>();

[0168] for (Entry<String, String[]>entry : APPLICATION_SERVER_DEPENDENCIES.entrySet()) {

[0169] if (!entry.getKey().equalsIgnoreCase(engine)) {excludedJarNamePrefixs.addAll(Arrays.asList(entry.getValue()));

[0170] }

[0171] }

[0172] List <url>filteredUrlList = new ArrayList<>();

[0173] / / Traverse the current url

[0174] for (final URL url : urls) {

[0175] String path = url.getPath();

[0176] / / Name normalization

[0177] if (path.endsWith(".jar! / ")) {

[0178] path = path.substring(0, path.length() - 2);

[0179] }

[0180] / / Non-.jar files are retained directly

[0181] if (!path.endsWith(".jar")) {

[0182] filteredUrlList.add(url);

[0183] continue;

[0184] }

[0185] / / Compare based on jar name

[0186] String jarName = path.substring(path.lastIndexOf(' / ') + 1);

[0187] if (excludedJarNamePrefixs.stream().noneMatch(jarName::startsWith)) {

[0188] / / Need to be retained

[0189] filteredUrlList.add(url);

[0190] } else {

[0191] / / Need to be discarded

[0192] System.out.println("discard->" + url);

[0193] }

[0194] }

[0195] return super.createClassLoader(filteredUrlList.toArray(new URL[0]));

[0196] }

[0197] By specifying the type of network.engine.type in the startup parameters, you can exclude other network engines from the dependent packages, thereby switching the underlying network engine.

[0198] It can be seen that the core of the present invention to realize dynamic switching of the underlying network engine based on the SpringBoot framework is to inherit JarLauncher and rewrite the createClassLoader method through a custom startup entry class, and dynamically filter the dependency packages of non-target engines according to the startup parameters in combination with the predefined APPLICATION_SERVER_DEPENDENCIES dependency mapping table; at the same time, JarLayout is extended through the custom Layout layout manager, and the custom startup class is embedded in the JAR package in the packaging stage and the MANIFEST.MF startup entry is modified, and the layout logic injection is realized in combination with the Maven plug-in configuration; 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 the conflicting dependencies according to the dependency prefix, thereby realizing seamless switching of multiple engines such as Tomcat and TongWeb. This solution realizes flexible engine switching in the deployment stage without modifying the business code through class loading control and dependency dynamic filtering mechanism, and has the advantages of compatibility, reusability and low maintenance cost.

[0199] The following table compares the response times used in the present invention and the prior art in corresponding directions:

[0200]

[0201] It is important to note that although the unit is seconds, in the financial services industry, the impact of a difference of a few seconds is very significant.

[0202] In addition, the present invention also includes an electronic device, comprising:

[0203] Memory for storing computer programs;

[0204] The processor is used to implement a method for quickly switching the underlying network engine of the program based on the SpringBoot framework when executing the program stored in the memory.

[0205] The present invention also includes a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, a method for quickly switching the underlying network engine of the program based on the SpringBoot framework is implemented.

[0206] Although the present invention is disclosed as above with preferred embodiments, it is not intended to limit the scope of implementation of the present invention. Any person skilled in the art may make some improvements without departing from the scope of the invention of the present invention, that is, all 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 the reference terms "one embodiment / method", "some embodiments / methods", "examples", "specific examples", or "some examples" means that the specific features, structures, materials or characteristics described in conjunction with the embodiment / method or example are included in at least one embodiment / method or example of the present application. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment / method or example. Moreover, the specific features, structures, materials or characteristics described can be combined in any one or more embodiments / methods or examples in a suitable manner. In addition, those skilled in the art can combine and combine the different embodiments / methods or examples described in this specification and the features of different embodiments / methods or examples without contradicting each other.

[0207] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features being referred to. Thus, a feature specified as "first" or "second" may explicitly or implicitly include at least one such feature. Throughout the description of this application, "plurality" means at least two, for example, two, three, etc., unless otherwise specifically defined.

[0208] Those skilled in the art will appreciate that the above embodiments are merely intended to clearly illustrate the present disclosure and are not intended to limit the scope of the present disclosure. Other changes or modifications may be made based on the above disclosure, and such changes or modifications are still within the scope of the present disclosure.< / url> < / string> < / string>

Claims

1. A method for quickly switching the underlying network engine of a program based on the SpringBoot framework, characterized in that: It includes two separate types of projects: runtime projects and packaging projects. The runtime projects include layout implementation classes and dynamic filtering rule engines; the packaging projects include built-in layout factories and class dynamic injection mechanisms. The layout factory packages business projects into customized classes through plug-ins based on the official main class layout. It completes the packaging project through a custom startup entry class, a custom Layout manager, and a custom ClassLoader. It also uses the custom Layout manager to quickly switch the underlying network engine. The custom Layout manager extends JarLayout and embeds the custom startup class into the final JAR package during the packaging phase, ensuring that the startup entry points to the custom logic. Combined with Maven plug-in configuration, it overrides the default packaging behavior and implements layout logic injection. Parameterized switching is performed during the deployment phase, and the target engine is specified through startup parameters to automatically eliminate conflicting dependencies. When customizing ClassLoader, you also need to rewrite methods, including: obtaining the network engine type from the startup parameter network.engine.type, counting the dependent package prefix set 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 ClassLoader.

2. The method for quickly switching the underlying network engine of a program based on the SpringBoot framework as claimed in claim 1, characterized in that: The custom startup entry class inherits JarLauncher and rewrites the createClassLoader method to dynamically exclude dependency packages of non-target engines based on system parameters; and identifies JAR packages of different engines through a predefined dependency mapping table.

3. The method for quickly switching the underlying network engine of a program based on the SpringBoot framework as claimed in claim 2, characterized in that: Compile the contents of the packaged project and push them to the Maven private server for use in subsequent projects.

4. The method for quickly switching the underlying network engine of a program based on the SpringBoot framework as claimed in claim 1, characterized in that: Define filtering packages when customizing ClassLoader. Specifically, define static APPLICATION_SERVER_DEPENDENCIES in the relevant class and configure the dependency package lists of different network engines respectively.

5. The method for quickly switching the underlying network engine of a program based on the SpringBoot framework according to any one of claims 1 to 4, characterized in that: The network engines supported by SpringBoot include at least two of Tomcat, Jetty, Undertow, and Netty.

6. The method for quickly switching the underlying network engine of a program based on the SpringBoot framework according to any one of claims 1 to 4, characterized in that: The network engine supported by SpringBoot also includes TongWeb.

7. An electronic device, characterized in that: include: Memory for storing computer programs; A processor, configured to implement the method according to any one of claims 1 to 6 when executing a program stored in a memory.

8. 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 a processor, the method according to any one of claims 1 to 6 is implemented.

Citation Information

Patent Citations

  • An exception handling method working in a hybrid mode execution engine

    CN102262537B

  • Low-coupling extended business system based on plug-in engine injection

    CN112363755A

  • Dependence management and tool integration method based on springboot

    CN115712456A