Configuration file loading method, apparatus and device

By obtaining and storing target configuration information from the configuration center before the preset third-party jar package in the project loads the local configuration file, the problem of being unable to automatically load the configuration file in the existing technology is solved, and the operating efficiency of the jar package is improved.

CN115469934BActive Publication Date: 2025-10-10CHINA UNITED NETWORK COMM GRP CO LTD +1
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202110651034.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-06-10
Publication Date
2025-10-10
Estimated Expiration
2041-06-10

AI Technical Summary

Technical Problem

In the prior art, when running a project containing a preset third-party jar package, it is impossible to automatically load the configuration file, resulting in project failure.

Method used

Before the preset third-party jar package in the project loads the local configuration file, it sends a request message to the configuration center to obtain the target configuration information, stores it as a local configuration file, and generates a local configuration file that meets the requirements.

Benefits of technology

It realizes the automatic loading of configuration files, improves the running efficiency of jar packages, and avoids the steps of manual processing of configuration files.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115469934B_ABST
    Figure CN115469934B_ABST
Patent Text Reader

Abstract

Embodiments of the present application provide a configuration file loading method, device and equipment, the method is applied to a server, the method comprises the following steps: before a preset third-party jar package in a project loads a local configuration file, sending request information to a configuration center, so that the configuration center returns target configuration information according to the request information; the project runs on the server; receiving the target configuration information, and loading the received target configuration information, generating a local configuration file meeting the requirements, so that the third-party jar package calls the local configuration file during running, the method obtains the required target configuration information before the third-party jar package loads the configuration file, and stores the target configuration information as a local configuration file according to preset requirements, without manual processing of the configuration file, so that the automatic loading of the configuration file can be realized, and the running efficiency of the jar package is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present invention relate to the field of Internet technology, and in particular to a configuration file loading method, apparatus, and device. Background Art

[0002] With the rapid development of the Internet, more and more offline configurations are being transferred to online unified management. That is, the configuration center is used to centrally manage configuration files in different projects and environments.

[0003] Normally, when a server runs a project, it automatically retrieves and packages the configuration files from the configuration center. However, when a project contains some preset third-party jar packages (Java Archive, Java archive files), the usage documentation will indicate that the server must store the preset configuration files locally to obtain the configuration files from the server when running the project. Since all configuration files are managed by the configuration center, no configuration files are stored locally on the server. In the prior art, a configuration file is usually written manually and stored locally on the server.

[0004] Therefore, there is a problem in the prior art that automatic loading of configuration files cannot be achieved when running a project containing a preset third-party jar package. Summary of the Invention

[0005] The embodiments of the present invention provide a configuration file loading method, apparatus and device to solve the problem that the configuration file cannot be automatically loaded when running a project containing a preset third-party jar package.

[0006] In a first aspect, an embodiment of the present invention provides a configuration file loading method, applied to a server, the method comprising:

[0007] Before the preset third-party jar package in the project loads the local configuration file, a request message is sent to the configuration center so that the configuration center returns the target configuration information according to the request message; the project runs on the server;

[0008] The target configuration information is received, and the received target configuration information is loaded to generate a local configuration file that meets the requirements, so that the third-party jar package can call the local configuration file at runtime.

[0009] Optionally, before the preset third-party jar package in the project loads the local configuration file, send a request message to the configuration center, including:

[0010] Monitor whether the project is started through a listener; the listener is established in the project;

[0011] When a project containing a preset third-party jar package is detected to be started, a request message is sent to the configuration center.

[0012] Optionally, loading the received target configuration information to generate a local configuration file that meets the requirements includes:

[0013] Obtain the storage path information and file name information corresponding to the preset third-party jar package;

[0014] The obtained target configuration information is loaded into a temporary folder at a storage location corresponding to the storage path information, and the name of the temporary folder is modified according to the file name information to obtain a local configuration file that meets the requirements.

[0015] Optionally, the request information includes a server type and configuration identification information, and sending the request information to the configuration center so that the configuration center returns target configuration information according to the request information includes:

[0016] Sending a request message including the server type and configuration identification information to the configuration center, so that the configuration center determines the storage space where the target configuration information is located according to the server type, and determines the target configuration information according to the configuration identification information.

[0017] Optionally, the folder to which the local configuration file belongs is a temporary folder. After the third-party jar package calls the local configuration file at runtime, the method further includes: executing an operation of clearing the temporary folder.

[0018] Optionally, before the preset third-party jar package in the project loads the local configuration file, send a request message to the configuration center, including:

[0019] Check whether there is a preset third-party jar package in the project. If there is a preset third-party jar package, send a request message to the configuration center before the preset third-party jar package in the project loads the local configuration file.

[0020] In a second aspect, an embodiment of the present invention provides a configuration file loading device, the device comprising:

[0021] A sending module is used to send a request message to the configuration center before the preset third-party jar package in the project loads the local configuration file, so that the configuration center returns the target configuration information according to the request message; the project runs on the server;

[0022] The processing module is used to receive the target configuration information, load the received target configuration information, and generate a local configuration file that meets the requirements, so that the third-party jar package can call the local configuration file at runtime.

[0023] In a third aspect, an embodiment of the present invention provides an electronic device, including: at least one processor and a memory;

[0024] The memory stores computer-executable instructions;

[0025] The at least one processor executes the computer-executable instructions stored in the memory, so that the at least one processor performs the method as described in any one of the first aspects.

[0026] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, wherein the storage medium stores a computer program, and when the computer program is executed by a processor, the method as described in any one of the first aspects is implemented.

[0027] In a fifth aspect, an embodiment of the present invention provides a program product, comprising a computer program, which, when executed by a processor, implements the method as described in any one of the first aspects.

[0028] An embodiment of the present invention provides a configuration file loading method, device and equipment, which is applied to a server. The method includes: before a preset third-party jar package in a project loads a local configuration file, sending request information to a configuration center so that the configuration center returns target configuration information according to the request information; the project is run on the server; the target configuration information is received, and the received target configuration information is loaded to generate a local configuration file that meets the requirements, so that the third-party jar package can call the local configuration file during operation. The method obtains the required target configuration information before the third-party jar package loads the configuration file, and stores it as a local configuration file according to preset requirements, without the need for manual processing of the configuration file, thereby realizing automatic loading of the configuration file and improving the operation efficiency of the jar package. BRIEF DESCRIPTION OF THE DRAWINGS

[0029] 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. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0030] Figure 1 A schematic diagram of an application scenario for loading a configuration file provided by an embodiment of the present invention;

[0031] Figure 2 A flow chart of a configuration file loading method provided by an embodiment of the present invention;

[0032] Figure 3A schematic diagram of a configuration file loading method provided in an embodiment of the present invention;

[0033] Figure 4 A schematic diagram of the structure of a configuration file loading device provided by an embodiment of the present invention;

[0034] Figure 5 A schematic diagram of the hardware structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0035] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of the present invention.

[0036] The terms "first", "second", "third", "fourth", etc. (if any) in the description and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that the numbers used in this way can be interchanged where appropriate, so that the embodiments of the invention described herein can, for example, be implemented in orders other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or apparatus that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or apparatus.

[0037] Figure 1 A schematic diagram of an application scenario of configuration file loading provided by an embodiment of the present invention, such as Figure 1 As shown, online configuration refers to the management of configuration files for different environments through a configuration center 101, such as Apollo, a distributed configuration center. The configuration center 101 includes multiple command spaces, each of which corresponds to the configuration files required for different environments. A configuration center supports providing configuration files to multiple servers 102. When the server needs to call a configuration file, it can automatically go to the configuration center to obtain the configuration file and package it. There is no need to configure the configuration files in different environments offline, nor is there any need to manually select the configuration file in the environment, package it, and upload it to the server when the server calls the configuration file.

[0038] However, when a project includes a preset third-party JAR package, due to the special nature of the preset third-party JAR package, it requires the required configuration files to be stored locally on the server so that the preset third-party JAR package can load the configuration files from the local server. However, since the configuration files of all projects are currently managed centrally through the configuration center, the corresponding configuration files are no longer stored locally. Therefore, when running a project that includes a preset third-party JAR package, the configuration files cannot be automatically loaded, causing the project to fail.

[0039] Based on the above problems, the configuration file loading method provided by the embodiment of the present invention sends a request information to the configuration center before the preset third-party jar package in the project loads the local configuration file, so that the configuration center returns the target configuration information according to the request information, and then stores the obtained target configuration information locally on the server, so as to realize the process of automatically loading the configuration file of the preset third-party jar package and improve the operating efficiency of the jar package.

[0040] The following specific embodiments are used to describe the technical solution of the present invention in detail. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described in detail in some embodiments.

[0041] Figure 2 A flow chart of a configuration file loading method provided by an embodiment of the present invention is shown as follows: Figure 2 As shown, the method includes:

[0042] S201. Before a preset third-party jar package in a project loads a local configuration file, a request message is sent to a configuration center so that the configuration center returns target configuration information according to the request message; the project is run on a server;

[0043] S202: Receive the target configuration information, load the received target configuration information, and generate a local configuration file that meets the requirements, so that the third-party jar package can call the local configuration file during runtime.

[0044] In this embodiment, a project refers to a software product developed by a developer that implements a certain function. A project runs on a server. Depending on user needs, a project can be run on different types of servers. For example, in a test environment, the project can be run on a test server; in a production environment, the project can be run on a production server.

[0045] In this embodiment, the project will rely on some jar packages. The jar package is a platform-independent file format that can combine multiple files into one file. The third-party jar package is a file written by a third party. The method of the third-party jar package can be implemented by calling the third-party jar package.

[0046] The running condition of the preset third-party jar package in this embodiment includes storing the local configuration file (that is, the local properties file) required by the preset third-party jar package on the local server. Therefore, when running a project, if the project contains the preset third-party jar package, the preset third-party jar package obtains the configuration file from the local server.

[0047] In order to automate the process of running a project that contains a third-party jar package without manually processing the configuration file, this application sends a request to the configuration center before the project's preset third-party jar package loads the local configuration file to obtain the target configuration information corresponding to the third-party jar package. Among them, the number of preset third-party jar packages in a project can be one or more, so it is necessary to obtain the configuration information from the configuration center and generate the local configuration file before the first preset third-party jar package loads the local configuration file.

[0048] Specifically, the server will send a request message to the configuration center. The request message is used to obtain the target configuration information corresponding to the preset third-party jar package. When the configuration center receives the request message, it will determine the target configuration information based on the request message and send it to the server. After receiving the target configuration information, the server will store the target configuration information in the form of a local configuration file. Specifically, this can be achieved by overriding the contextInitialized method. What the method needs to achieve is to obtain the target configuration information from the configuration center and write it as a local configuration file. In addition, after overriding the contextInitialized method, it is necessary to continue to execute the parent class super.contextInitialized(event) method to continue executing the content corresponding to other codes in the project.

[0049] After the local configuration file is generated, when the preset third-party jar package in the project is run to load the configuration file, the configuration file will be obtained from the location required by the preset third-party jar package and the project will continue to run.

[0050] The following is a specific example illustrating the use case of this application. For a payment company, upon completing a transaction, we will settle the account and collect a handling fee from the merchant. When collecting the handling fee, we need to issue an invoice to the merchant. This invoicing requires accessing an interface to the invoice issuing department, which is a third-party JAR package. This process involves sending a request to the relevant department, and the relevant department's usage documentation indicates that a configuration file from a specified location is required. In other words, the third-party JAR package requires accessing the configuration file from a specified location. The usage documentation includes storage path information, file name information, and configuration identification information, such as the configuration identification information corresponding to the network address. To issue an invoice in a test environment, the project needs to be run on a test server. Using the method of this application, the network address of the test environment is stored as a local configuration file from the configuration center. When the project is run on the test server, the network address of the test environment is loaded, and the invoice for the test environment is issued. To issue an invoice in a production environment, the project needs to be run on a production server. Using the method of this application, the network address of the production environment is stored as a local configuration file from the configuration center. When the project is run on the production server, the network address of the production environment is loaded, and the actual invoice is issued.

[0051] The configuration file loading method provided by the embodiment of the present invention sends a request message to the configuration center before the preset third-party jar package in the project loads the local configuration file, so that the configuration center returns the target configuration information according to the request information; the project is run on the server; the target configuration information is received, and the received target configuration information is loaded to generate a local configuration file that meets the requirements, so that the third-party jar package can call the local configuration file during operation. Through the above method, the configuration information of the configuration center can be stored locally on the server, so as to realize automatic loading of the configuration file when running the project containing the preset third-party jar package, thereby improving the operation efficiency of the jar package.

[0052] In one embodiment, before the preset third-party jar package in the project loads the local configuration file, a request message is sent to the configuration center, including:

[0053] The listener monitors whether the project is started; the listener is established in the project; when the project containing the preset third-party jar package is started, a request message is sent to the configuration center.

[0054] In this embodiment, the number of pre-set third-party JAR packages in a project is uncertain. Therefore, the step of sending a request message to the configuration center must be executed at a certain time before any pre-set third-party JAR package loads the local configuration file. To meet this condition, the time is set as the project startup time. That is, when the project starts, the request message is sent, which can meet the requirements of all pre-set third-party JAR packages loading configuration files.

[0055] Specifically, by setting a listener in the project, the listener can monitor whether the project is started. When the project is started, the step of sending the request information is executed. Specifically, the method for setting a listener in the project is to create a new xxxListener class in the project. This class needs to inherit the ServletContextListener class. By inheriting the ServletContextListener class, the listener can monitor the project startup.

[0056] In addition, you need to configure the listener in the web.xml file, which is used to initialize the configuration information, for example, <listener-class> com.unicompayment.cn.xxxListener< / listener-class> , this statement can be used to configure the listener in the web.xml file.

[0057] By setting a listener to monitor whether the project is started and executing the step of sending request information to the configuration center when the project starts, it can ensure that the target configuration information is obtained from the configuration center and the local configuration file is generated before the preset third-party jar package in the project loads the local configuration file.

[0058] In one embodiment, the received target configuration information is loaded to generate a local configuration file that meets the requirements, including:

[0059] Obtain the storage path information and file name information corresponding to the preset third-party jar package; load the obtained target configuration information into a temporary folder at the storage location corresponding to the storage path information, and modify the name of the temporary folder according to the file name information to obtain a local configuration file that meets the requirements.

[0060] Among them, after receiving the target configuration file, the server needs to load the target configuration file to obtain a local configuration file that meets the requirements. Among them, the process of loading the received configuration information is to store the configuration information in a preset storage path with a preset name. Among them, the preset third-party jar package contains a usage document, in which the storage requirements for the local configuration file are recorded, such as the storage path of the local configuration file and the file name information of the local configuration file. Therefore, when loading the target configuration information and generating a local configuration file that meets the requirements, it is necessary to first read the usage document of the preset third-party jar package, obtain the storage path information and file name information, and then load the obtained target configuration information into a temporary folder at a location corresponding to the storage path information, and modify the name of the temporary folder according to the file name information.

[0061] For example, for a preset third-party jar package, it requires the local configuration file to store the target configuration information in a temporary folder on the D drive with the name A. After obtaining the target configuration information, the target configuration information needs to be stored in a temporary folder on the D drive and the name is changed to A.

[0062] By obtaining the requirements of the preset third-party jar package for path information and file name information, the obtained target configuration information can be stored in a preset format to meet the requirements of the preset third-party jar package for the local configuration file.

[0063] In one embodiment, the request information includes a server type and configuration identification information, and sending the request information to the configuration center so that the configuration center returns target configuration information according to the request information includes:

[0064] Sending a request message including the server type and configuration identification information to the configuration center, so that the configuration center determines the storage space where the target configuration information is located according to the server type, and determines the target configuration information according to the configuration identification information.

[0065] In this embodiment, the process of determining the target configuration information needs to be based on the type and configuration identification information of the server. Figure 3 The schematic diagram of the configuration file loading method provided by the embodiment of the present invention is as follows: Figure 3As shown, the configuration center is divided into different storage spaces, such as storage space 1 and storage space 2, wherein different storage spaces store configuration information in different environments. The types of servers include test servers and production servers, and when a project needs to be tested, the project is run in a test server. When the test server sends a request to the configuration center, it needs to obtain the type of the server, and through the type of the server, the running environment of the project can be determined, and then the configuration center can determine the storage space where the target configuration information is located.

[0066] In addition, the server also needs to send configuration identification information to the configuration center to obtain the target configuration information in the determined storage space. Since the configuration information required by the preset third-party jar package during runtime is not all the information stored in the storage space, but part of the configuration information. Since the configuration information in the configuration center is stored in the form of key-value pairs, that is, one key-value pair corresponds to one configuration information, the configuration identification information can be key-value information. The key-value information is obtained from the usage document of the preset third-party jar package.

[0067] For example, the obtained configuration information can be network address information or timeout time. Through the network address information, the calling address can be determined, and according to the timeout information, after the time corresponding to the timeout information is exceeded, a timeout prompt information can be fed back.

[0068] For the configuration center, when the type of the server and the configuration identification information are obtained, the storage space of the target configuration information and the target configuration information in the storage space can be determined.

[0069] By sending the server type and the configuration identification information, the configuration center can determine the target configuration information, so as to ensure that the obtained local configuration file is the local configuration file required by the preset third-party jar package.

[0070] In an embodiment, the folder to which the local configuration file belongs is a temporary folder, and after the third-party jar package calls the local configuration file during runtime, the operation of cleaning the temporary folder is further performed.

[0071] In this embodiment, in order to meet the running conditions of the preset third-party jar package, a temporary folder can be set on the server for storing the local configuration file. When the preset third-party jar package in the project calls the local configuration file, the temporary folder can be cleaned to avoid storing the local configuration file on the server for a long time, avoid server lag caused by too many local configuration files, and affect the running of the project. Therefore, when running a project containing a preset third-party jar package each time, it is necessary to realize obtaining target configuration information from the configuration center and loading the target configuration information to generate a local configuration file.

[0072] In one embodiment, before the preset third-party jar package in the project loads the local configuration file, a request message is sent to the configuration center, including:

[0073] Check whether there is a preset third-party jar package in the project. If there is a preset third-party jar package, send a request message to the configuration center before the preset third-party jar package in the project loads the local configuration file.

[0074] Specifically, the method for detecting the preset third-party jar package can be: running the project on the server. If an error message appears during the running of the project, and the error message is that the preset third-party jar package is not successfully loaded into the configuration file, it can be determined that the project has a preset third-party jar package.

[0075] Alternatively, it is also possible to determine whether there is a preset third-party jar package by statement detection. For example, when it is detected that the name of the jar package is a preset name, it can be determined that there is a preset third-party jar package in the project.

[0076] The above method can accurately determine whether a preset third-party jar package exists in the project, without the need to manually determine whether the preset third-party jar package is included.

[0077] Figure 4 A schematic diagram of the structure of a configuration file loading device provided by an embodiment of the present invention. Figure 4 As shown, the configuration file loading device 40 of this embodiment may include: a sending module 401 and a processing module 402.

[0078] The sending module 401 is used to send a request message to the configuration center before the preset third-party jar package in the project loads the local configuration file, so that the configuration center returns the target configuration information according to the request message; the project runs on the server;

[0079] The processing module 402 is used to receive the target configuration information, load the received target configuration information, and generate a local configuration file that meets the requirements, so that the third-party jar package can call the local configuration file during runtime.

[0080] Optionally, the sending module 401 is specifically configured to:

[0081] Monitor whether the project is started through a listener; the listener is established in the project;

[0082] When a project containing a preset third-party jar package is detected to be started, a request message is sent to the configuration center.

[0083] Optionally, when loading the received target configuration information and generating a local configuration file that meets the requirements, the processing module 402 is specifically configured to:

[0084] Obtain the storage path information and file name information corresponding to the preset third-party jar package;

[0085] The obtained target configuration information is loaded into a temporary folder at a storage location corresponding to the storage path information, and the name of the temporary folder is modified according to the file name information to obtain a local configuration file that meets the requirements.

[0086] Optionally, when the sending module 401 sends request information to the configuration center so that the configuration center returns target configuration information according to the request information, it is specifically configured to:

[0087] Sending a request message including the server type and configuration identification information to the configuration center, so that the configuration center determines the storage space where the target configuration information is located according to the server type, and determines the target configuration information according to the configuration identification information.

[0088] Optionally, the folder to which the local configuration file belongs is a temporary folder, and the device further includes: a clearing module;

[0089] The clearing module is used to clear the temporary folder after the third-party jar package calls the local configuration file at runtime.

[0090] Optionally, before the preset third-party jar package in the project loads the local configuration file, the sending module sends a request message to the configuration center, specifically for:

[0091] Before sending the request information to the configuration center, check whether there is a preset third-party jar package in the project. If there is a preset third-party jar package, send the request information to the configuration center before the preset third-party jar package in the project loads the local configuration file.

[0092] The configuration file loading device provided by the embodiment of the present invention can realize the above-mentioned Figure 2 and Figure 3 The configuration file loading method of the embodiment shown in the figure has similar implementation principles and technical effects, which will not be repeated here.

[0093] Figure 5 Schematic diagram of the hardware structure of the electronic device provided by the embodiment of the present invention. Figure 5 As shown, the electronic device 50 provided in this embodiment includes: at least one processor 501 and a memory 502. The processor 501 and the memory 502 are connected via a bus 503.

[0094] During the specific implementation process, at least one processor 501 executes the computer-executable instructions stored in the memory 502, so that the at least one processor 501 executes the configuration file loading method in the above method embodiment.

[0095] The specific implementation process of the processor 501 can be found in the above method embodiment. Its implementation principle and technical effects are similar and will not be repeated here in this embodiment.

[0096] In the above Figure 5 In the illustrated embodiment, it should be understood that the processor may be a central processing unit (CPU), other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASICs), etc. A general-purpose processor may be a microprocessor or any conventional processor. The steps of the method disclosed in the present invention may be directly executed by a hardware processor or by a combination of hardware and software modules within the processor.

[0097] The memory may include a high-speed RAM memory, and may also include a non-volatile storage NVM, such as at least one disk storage.

[0098] The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus. Buses can be classified into address buses, data buses, and control buses. For ease of illustration, the buses in the drawings of this application are not limited to just one bus or just one type of bus.

[0099] An embodiment of the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer-executable instructions. When a processor executes the computer-executable instructions, the configuration file loading method of the above method embodiment is implemented.

[0100] The computer readable storage medium described above can be implemented by any type of volatile or nonvolatile storage devices or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk or optical disk. The readable storage medium can be any available medium that can be accessed by a general or special purpose computer.

[0101] An exemplary readable storage medium is coupled to the processor, so that the processor can read information from the readable storage medium, and can write information to the readable storage medium. Of course, the readable storage medium can also be an integral part of the processor. The processor and the readable storage medium can be located in an application specific integrated circuit (ASIC). Of course, the processor and the readable storage medium can also exist as discrete components in the device.

[0102] One embodiment of the present application provides a computer program product comprising a computer program, which, when executed by a processor, implements the configuration file loading method provided in any of the embodiments corresponding to the computer program and the processor. Figure 2 and Figure 3 The computer program product comprises a computer program, which, when executed by a processor, implements the configuration file loading method provided in any of the embodiments corresponding to the computer program and the processor.

[0103] Those skilled in the art can understand that all or part of the steps of the above-mentioned method embodiments can be completed by program instruction-related hardware. The foregoing program can be stored in a computer readable storage medium. The program, when executed, executes steps including the above-mentioned method embodiments; and the foregoing storage medium includes ROM, RAM, magnetic disk or optical disk and various program code storage media.

[0104] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, and not to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that they can still modify the technical solutions recorded in the foregoing embodiments, or make equivalent replacements to part or all of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the scope of the technical solutions of the embodiments of the present application.

Claims

1. A configuration file loading method, characterized in that: Applied to a server, the method includes: Before the preset third-party jar package in the project loads the local configuration file, a request message is sent to the configuration center so that the configuration center returns the target configuration information according to the request message; the project runs on the server; Receive the target configuration information, load the received target configuration information, and generate a local configuration file that meets the requirements, so that the third-party jar package can call the local configuration file at runtime; Before the preset third-party jar package in the project loads the local configuration file, a request message is sent to the configuration center, including: Monitor whether the project is started through a listener; the listener is established in the project; When monitoring the startup of a project containing a preset third-party jar package, a request message is sent to the configuration center; The monitoring of whether the project is started by using a listener includes: creating a new xxxListener class in the project, the xxxListener class inherits the ServletContextListener class, and the ServletContextListener class is used to monitor whether the project is started.

2. The method according to claim 1, characterized in that Load the received target configuration information and generate a local configuration file that meets the requirements, including: Obtain the storage path information and file name information corresponding to the preset third-party jar package; The obtained target configuration information is loaded into a temporary folder at a storage location corresponding to the storage path information, and the name of the temporary folder is modified according to the file name information to obtain a local configuration file that meets the requirements.

3. The method according to claim 1, characterized in that The request information includes the server type and configuration identification information, and sending the request information to the configuration center so that the configuration center returns the target configuration information according to the request information includes: Sending a request message including the server type and configuration identification information to the configuration center, so that the configuration center determines the storage space where the target configuration information is located according to the server type, and determines the target configuration information according to the configuration identification information.

4. The method according to claim 1, wherein The folder to which the local configuration file belongs is a temporary folder. After the third-party jar package calls the local configuration file at runtime, the method further includes: executing an operation of clearing the temporary folder.

5. The method according to any one of claims 1 to 4, characterized in that Before the preset third-party jar package in the project loads the local configuration file, it sends a request message to the configuration center, including: Check whether there is a preset third-party jar package in the project. If there is a preset third-party jar package, send a request message to the configuration center before the preset third-party jar package in the project loads the local configuration file.

6. A configuration file loading device, characterized in that: The device comprises: A sending module is used to send a request message to the configuration center before the preset third-party jar package in the project loads the local configuration file, so that the configuration center returns the target configuration information according to the request message; the project runs on the server; A processing module is used to receive the target configuration information, load the received target configuration information, and generate a local configuration file that meets the requirements, so that the third-party jar package can call the local configuration file at runtime; The sending module is further configured to monitor whether the project is started through a listener; the listener is established in the project; and when the startup of the project containing the preset third-party jar package is monitored, a request message is sent to the configuration center; The sending module is further used to create a new xxxListener class in the project, where the xxxListener class inherits the ServletContextListener class, and the ServletContextListener class is used to monitor whether the project is started.

7. An electronic device, characterized in that: include: at least one processor and memory; The memory stores computer-executable instructions; The at least one processor executes the computer-executable instructions stored in the memory, so that the at least one processor performs the method according to any one of claims 1 to 5.

8. A computer-readable storage medium, characterized in that The 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 5 is implemented.

9. A program product comprising a computer program, characterized in that When the computer program is executed by a processor, the method according to any one of claims 1 to 5 is implemented.

Citation Information

Patent Citations

  • Configuration information push method and system, and configuration information receiving method and system

    CN107947960A

  • Dynamic data source switching method and device under SpringBoot framework, equipment and storage medium

    CN110209438A

  • Configuration file loading method and system

    CN110569085A