Configuration management methods, devices, equipment, and media based on Spring Boot
By introducing the inheritedPrefix property and extending the ConfigurationPropertiesBinder class into the Spring Boot framework, the problem of Spring Boot's inability to support multiple Redis instance connections is solved, enabling configuration inheritance and personalized adjustments, and generating configuration objects that include default and specific environment changes.
Patent Information
- Application Number
- CN202511232737.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-01
- Publication Date
- 2025-10-31
- Estimated Expiration
- 2045-09-01
AI Technical Summary
The Spring Boot framework does not support parallel connections to multiple Redis instances. Existing methods cannot implement configuration inheritance, which means that each Redis instance needs to have all configuration items set completely, making configuration inheritance impossible.
In Spring Boot, the `inheritedPrefix` attribute is introduced into the `@ConfigurationProperties` annotation, and the `@ConfigurationPropertiesBinder` class is extended. By detecting whether the `inheritedPrefix` value is specified in the annotation, the configuration with that prefix is read first as the default setting, and the configuration specified in the annotation is used as the changed part in a specific environment, thus realizing configuration inheritance.
It implements a configuration inheritance mechanism, generating configuration object instances that include both default settings and personalized adjustments, and supports parallel connections to multiple Redis instances.
Smart Images

Figure CN120743338B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a configuration management method, apparatus, device, and medium based on Spring Boot. Background Technology
[0002] Spring Boot's design did not take into account the need for multiple configuration scenarios for the same type of service. Specifically, when it is necessary to connect to different Redis servers in the same application, its autowiring function cannot meet this requirement. This is because Spring Boot's built-in configuration items prefixed with spring.data.redis only support configuring the connection information of one Redis client instance, which means it can only bind one RedisProperties configuration bean, and therefore cannot support parallel connections to multiple Redis instances.
[0003] To support diverse configuration needs, a common approach is to create a custom configuration class, such as `CustomRedisProperties`. This custom class inherits from the default `RedisProperties` class provided by Spring Boot and adds the `@ConfigurationProperties(prefix = "foo.redis")` annotation to the custom class so that the system can read and process configuration items prefixed with `foo.redis`. However, this method does not support configuration inheritance. This means that when configuring each instance, all configuration items need to be completely set, even if most of the configuration remains unchanged. Therefore, how to achieve data inheritance during the configuration process of configuration objects is a technical problem that needs to be solved. Summary of the Invention
[0004] In view of this, the purpose of this invention is to provide a configuration management method, apparatus, device, and medium based on Spring Boot, which can extend annotations in the Spring Boot framework and implement a configuration inheritance mechanism. The specific solution is as follows:
[0005] Firstly, this application provides a configuration management method based on Spring Boot, including:
[0006] The target annotation is located in the target framework. A preset inheritance prefix is added to each target annotation. The initial method corresponding to the configuration property binder in the target framework is modified to obtain the corresponding modified method. The target framework is the Spring Boot framework.
[0007] Each of the target annotations is set as a parameter of the modified method, and it is determined whether the preset inheritance prefix has been added to the current target annotation in the modified method. If the preset inheritance prefix has been added to the current target annotation, a target configuration list is created.
[0008] If the prefix of the key-value pair corresponding to the current configuration item in the target configuration list matches the preset inherited prefix, then the prefix corresponding to the current configuration item is replaced with the preset original prefix in the target framework to obtain the new configuration item corresponding to the current configuration item.
[0009] A target binder is created based on the target configuration list. If the target framework explicitly defines a preset key value corresponding to the preset original prefix, the key value in the new configuration item is replaced with the preset key value corresponding to the preset original prefix to obtain the corresponding replaced configuration item. The target binder is then used to bind the key value in the replaced configuration item to the target configuration object to achieve the inheritance of configuration by different configuration objects.
[0010] Optionally, the creation of the target configuration list includes:
[0011] Obtain the configuration file list corresponding to each configuration item in the target framework, use the configuration file list as a parameter of a preset constructor, and use the preset constructor and the configuration file list to create the target configuration list.
[0012] Optionally, before replacing the key value in the new configuration item with the preset key value corresponding to the preset original prefix, the method further includes:
[0013] The key-value pairs corresponding to the new configuration item are placed into a preset initial Map object to obtain the corresponding target Map object, and a target resource storage class is created based on the target Map object; wherein, the target resource storage class is used to store the key-value pairs corresponding to the new configuration item;
[0014] The target resource storage class is placed at the end of the target configuration list so that the priority of the key-value pair corresponding to the new configuration item in the target resource storage class is lower than the priority of the preset key-value pair corresponding to the preset original prefix.
[0015] Optionally, placing the target resource storage class at the end of the target configuration list includes:
[0016] Invoke the preset addLast method corresponding to the target configuration list, and use the preset addLast method to place the target resource storage class at the end of the target configuration list.
[0017] Optionally, the Spring Boot-based configuration management method further includes:
[0018] If the preset inheritance prefix is not added to the current target annotation, the key value corresponding to the preset original prefix is bound to the corresponding target configuration object using the configuration attribute binder in the target framework.
[0019] Optionally, the Spring Boot-based configuration management method further includes:
[0020] After receiving the data refresh instruction, the process jumps to the step of setting each of the target annotations as parameters of the modified method, so as to rebind the key values corresponding to each of the target configurations.
[0021] Optionally, the Spring Boot-based configuration management method further includes:
[0022] Determine the data configuration requirements corresponding to each target configuration object in the current application scenario, and set the data processing logic corresponding to the preset inheritance prefix according to the data configuration requirements corresponding to each target configuration object;
[0023] The configuration inheritance strategy corresponding to the data processing logic is used to bind each key-value pair in the target framework to the corresponding target configuration object.
[0024] Secondly, this application provides a configuration management device based on Spring Boot, including:
[0025] The method modification module is used to find target annotations in the target framework, add a preset inheritance prefix to each target annotation, and modify the initial method corresponding to the configuration property binder in the target framework to obtain the corresponding modified method; wherein, the target framework is the Spring Boot framework;
[0026] The configuration list creation module is used to set each of the target annotations as parameters of the modified method, and to determine whether the preset inheritance prefix has been added to the current target annotation in the modified method. If the preset inheritance prefix has been added to the current target annotation, then a target configuration list is created.
[0027] The prefix replacement module is used to replace the prefix of the key-value pair corresponding to the current configuration item in the target configuration list with the preset inherited prefix if the prefix of the key-value pair matches the preset inherited prefix, so as to obtain the new configuration item corresponding to the current configuration item.
[0028] The data binding module is used to create a target binder based on the target configuration list. If the target framework explicitly defines a preset key value corresponding to the preset original prefix, the key value in the new configuration item is replaced with the preset key value corresponding to the preset original prefix to obtain the corresponding replaced configuration item. The target binder is then used to bind the key value in the replaced configuration item to the target configuration object to achieve the inheritance of configuration by different configuration objects.
[0029] Thirdly, this application provides an electronic device, comprising:
[0030] Memory, used to store computer programs;
[0031] A processor for executing the computer program to implement the aforementioned Spring Boot-based configuration management method.
[0032] Fourthly, this application provides a computer-readable storage medium for storing a computer program that, when executed by a processor, implements the aforementioned Spring Boot-based configuration management method.
[0033] In this application, the target annotations are first located in the target framework. A preset inheritance prefix is added to each target annotation, and the initial method corresponding to the configuration property binder in the target framework is modified to obtain the corresponding modified method; wherein, the target framework is Spring. The system boots a framework, sets each target annotation as a parameter of the modified method, and determines whether the preset inheritance prefix has been added to the current target annotation in the modified method. If the preset inheritance prefix has been added to the current target annotation, a target configuration list is created. If the prefix of the key-value pair corresponding to the current configuration item in the target configuration list matches the preset inheritance prefix, the prefix corresponding to the current configuration item is replaced with the preset original prefix in the target framework to obtain the new configuration item corresponding to the current configuration item. Finally, a target binder is created based on the target configuration list. If the target framework explicitly defines the preset key-value corresponding to the preset original prefix, the key-value in the new configuration item is replaced with the preset key-value corresponding to the preset original prefix to obtain the corresponding replaced configuration item. The target binder is then used to bind the key-value in the replaced configuration item to the target configuration object to achieve configuration inheritance between different configuration objects. Therefore, this application extends annotations in the Spring Boot framework so that when Spring Boot starts and loads configurations, if a target annotation specifies a preset inheritance prefix, the configuration corresponding to that prefix will be read first as the default setting. The configuration corresponding to the original preset prefix in the annotation will then be used as the modified part for specific environments, overriding the default configuration. In this way, this method successfully implements a configuration inheritance mechanism, enabling the generation of configuration object instances that include both default settings and personalized adjustments. Attached Figure Description
[0034] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0035] Figure 1 This application discloses a flowchart of a configuration management method based on Spring Boot.
[0036] Figure 2 This is a schematic diagram of a specific configuration management method based on Spring Boot disclosed in this application;
[0037] Figure 3 This is a schematic diagram of one configuration data disclosed in this application;
[0038] Figure 4 This is a schematic diagram of the configuration management device structure based on Spring Boot disclosed in this application;
[0039] Figure 5 This is a structural diagram of an electronic device disclosed in this application. Detailed Implementation
[0040] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0041] To support diverse configuration needs, a common approach is to create a custom class that inherits from Spring Boot's default RedisProperties class and adds annotations to it. However, this method suffers from the problem that configurations cannot be inherited. Therefore, this application provides a Spring Boot-based configuration management method that extends annotations within the framework to implement a configuration inheritance mechanism.
[0042] See Figure 1 As shown in the figure, this embodiment of the invention discloses a configuration management method based on Spring Boot, including:
[0043] Step S11: Locate the target annotation in the target framework, add a preset inheritance prefix to each target annotation, and modify the initial method corresponding to the configuration property binder in the target framework to obtain the corresponding modified method; wherein, the target framework is the Spring Boot framework.
[0044] Spring Boot's design doesn't consider the need for multiple configurations of the same type of service. Specifically, when connecting to different Redis servers within the same application, its autowiring function cannot meet this requirement. This is because Spring Boot's built-in configuration items prefixed with `spring.data.redis` only support configuring connection information for one Redis client instance, meaning it can only bind to one `RedisProperties` configuration bean, thus failing to support parallel connections to multiple Redis instances. Therefore, to support multiple configuration needs, a common approach is to create a custom configuration class, for example, named `CustomRedisProperties`. This custom configuration class inherits from the default `RedisProperties` class provided by Spring Boot and adds the `ConfigurationProperties(prefix = "foo.redis")` annotation to the custom class so that it can read and process configuration items prefixed with `foo.redis`. However, the above approach has a drawback: it cannot achieve configuration inheritance. This means that when configuring each instance, all configuration items need to be completely set again, even if most of the configurations remain unchanged. Ideally, this embodiment aims to maintain some configurations at common default values, while only customizing configuration items that need to be changed. Taking Redis configuration as an example, parameters such as connection pool size and username / password are typically set to default values, while parameters such as host and port may need to be customized based on different environments or requirements. In this embodiment, configuration 1 is intended to be equivalent to configuration 2, where the code for configuration 1 and configuration 2 is as follows:
[0045] Configuration 1:
[0046] spring.data.redis: host: 192.168.1.100 port: 16379 username: userpassword: secret foo.redis:host: 192.168.1.101;
[0047] Configuration 2:
[0048] spring.data.redis:host: 192.168.1.100 port: 16379 username: userpassword: secret foo.redis:host: 192.168.1.101 port: 16379 username: userpassword: secret;
[0049] In other words, this embodiment aims to ensure that when the same application connects to different Redis servers, the same configurations, such as username and password, can be inherited between the servers without repeated configuration.
[0050] To achieve the above objectives, this solution creatively introduces a new attribute called `inheritedPrefix` into the `@ConfigurationProperties` annotation of Spring Boot, and also extends the built-in `@ConfigurationPropertiesBinder` class of Spring Boot. When Spring Boot starts and loads the configuration, if it detects that a `@ConfigurationProperties` annotation specifies a value of `inheritedPrefix`, the system will preferentially read the configuration corresponding to that prefix as the default setting, while the configuration specified by the `prefix` attribute in the annotation will be used as the modified part in a specific environment to override the default configuration. In this way, this embodiment successfully implements a configuration inheritance mechanism, enabling the generation of configuration instances that include both default settings and personalized adjustments. The specific process of this embodiment is as follows: Figure 2 As shown, the getBinder method needs to be called first, with ConfigurationProperties as the parameter of the method. The method checks whether the current ConfigurationProperties has inheritedPrefix set, and based on the corresponding judgment result, the configuration data is bound to the target configuration object using the corresponding binder.
[0051] This example first needs to locate the target annotation (ConfigurationProperties annotation) in the Spring Boot framework, and then add a preset inheritance prefix (i.e., a new property named inheritedPrefix) to the target annotation. The code implementation is shown below:
[0052] @Retention(RetentionPolicy.RUNTIME)
[0053] @Documented
[0054] @Indexed
[0055] public @interface ConfigurationProperties {
[0056] / / ...
[0057] @AliasFor("value")
[0058] String prefix() default "";
[0059] / / Add inheritance annotation
[0060] String inheritedPrefix() default "";
[0061] This embodiment then modifies the initialization method (getBinder method) of the configuration property binder in the target framework (i.e., the ConfigurationPropertiesBinder class built into Spring Boot). By adding inheritedPrefix to the ConfigurationProperties annotation, it is possible to distinguish between the configuration that needs to be inherited and the configuration that needs to be changed.
[0062] Step S12: Set each of the target annotations as a parameter of the modified method, and determine whether the preset inheritance prefix has been added to the current target annotation in the modified method. If the preset inheritance prefix has been added to the current target annotation, then create a target configuration list.
[0063] In this embodiment, the modified `getBinder` method receives a `ConfigurationProperties` annotation object and a target object (i.e., the instance to which configuration properties need to be injected, such as `FooRedisProperties`) as parameters. Inside the modified `getBinder` method, it first checks whether the current `ConfigurationProperties` annotation has an `inheritedPrefix` attribute set. If the current `ConfigurationProperties` annotation defines `inheritedPrefix`, a target configuration list is created. This list is then used to construct a dedicated Binder object (i.e., a target binder) for the `ConfigurationProperties` annotation containing `inheritedPrefix`. It should be noted that if the current target annotation does not have a preset inheritance prefix, the key-value pair corresponding to the preset original prefix is bound to the corresponding target configuration object using the configuration property binder in the target framework. That is, if the current `ConfigurationProperties` annotation does not define `inheritedPrefix`, the default Binder object (`ConfigurationPropertiesBinder`) provided by Spring Boot is used directly. This avoids changing the existing behavior of the framework and ensures backward compatibility.
[0064] In this embodiment, the process of creating the target configuration list may specifically include: obtaining the configuration file list corresponding to each configuration item in the target framework, using the configuration file list as a parameter of the preset constructor, and using the preset constructor and the configuration file list to create the target configuration list; that is, using the configuration file list as a parameter of the constructor to create a MutablePropertySources object (i.e., the target configuration list) to store the configuration items in the configuration file.
[0065] Step S13: If the prefix of the key-value pair corresponding to the current configuration item in the target configuration list matches the preset inherited prefix, then replace the prefix corresponding to the current configuration item with the preset original prefix in the target framework to obtain the new configuration item corresponding to the current configuration item.
[0066] In this embodiment, all configuration properties of the configuration items in the MutablePropertySources object are traversed. If the key of a property (e.g., data.redis) matches the prefix corresponding to the inheritedPrefix in the ConfigurationProperties annotation property, then the inheritedPrefix prefix of the key (data.redis) is replaced with the prefix corresponding to the prefix in the ConfigurationProperties annotation property (foo.redis, i.e., the preset original prefix), generating a new key. The new key (key name) and the value of the original configuration item (key value) together form the new configuration item. For example:
[0067] Default configuration options:
[0068] spring.data.redis: host: 192.168.1.100 port: 16379 username: userpassword: secret;
[0069] Replace the prefix of the key name in the default configuration item from inheritedPrefix to prefix. For example, spring.data.redis.host is replaced with foo.redis.host, and spring.data.redis.port is replaced with foo.redis.port. The key value of the configuration item remains unchanged. For example, the original spring.data.redis.host:192.168.1.100 is replaced with spring.foo.redis.host: 192.168.1.100.
[0070] Step S14: Create a target binder based on the target configuration list. If the target framework explicitly defines a preset key value corresponding to the preset original prefix, replace the key value in the new configuration item with the preset key value corresponding to the preset original prefix to obtain the corresponding replaced configuration item. Then, use the target binder to bind the key value in the replaced configuration item to the target configuration object to achieve the inheritance of configuration by different configuration objects.
[0071] In this embodiment, before replacing the key-value pair in the new configuration item with the preset key-value pair corresponding to the preset original prefix, the method further includes: placing the key-value pair corresponding to the new configuration item into a preset initial Map object to obtain the corresponding target Map object, and creating a target resource storage class based on the target Map object; wherein, the target resource storage class is used to store the key-value pair corresponding to the new configuration item; placing the target resource storage class at the end of the target configuration list so as to set the priority of the key-value pair corresponding to the new configuration item in the target resource storage class to be lower than the priority of the preset key-value pair corresponding to the preset original prefix; the process of placing the target resource storage class at the end of the target configuration list includes: calling the preset addLast method corresponding to the target configuration list, and using the preset addLast method to place the target resource storage class at the end of the target configuration list; the above process is also: placing The new key and its corresponding configuration value are placed into a Map object (i.e., the initial Map object). Finally, a MapPropertySource object (the target resource storage class) is created. The MapPropertySource stores the default configuration (i.e., the key-value pairs corresponding to the new configuration items). Then, the MapPropertySource created in the previous step is appended to the end of the configuration list (MutablePropertySources) by calling the addLast method of MutablePropertySources. This way, it can be overwritten. Specifically, the key-value pairs corresponding to the new configuration items are added to the end of MutablePropertySources to ensure that their priority is lower than the original configuration (e.g., foo.redis.*). In this way, the subsequently explicitly defined `foo.redis.host` can override the inherited value. Specifically, after adding `MapPropertySource` to the end of `MutablePropertySources`, a `Binder` object is created using the `MutablePropertySources` object and some other parameters. Then, the configuration value corresponding to the prefix of `ConfigurationProperties` is bound to the configuration object through the `Binder` object. For example, if `foo.redis.host: 192.168.1.101` is explicitly defined in `application.yml` of the target framework, then `foo.redis.host: 192.168.1.100` in `MapPropertySource` will be overridden, while undefined properties (such as `foo.redis.port`) will retain the inherited default value of 16379.
[0072] In one specific implementation, you can create a FooRedisProperties class and a BarRedisProperties class, and add the @ConfigurationProperties annotation to the class, as shown in the following code:
[0073] @ConfigurationProperties(prefix="foo.redis",inheritedPrefix="spring.data.redis") public class FooRedisProperties extends RedisProperties{…};
[0074] @ConfigurationProperties(prefix="bar.redis",inheritedPrefix="spring.data.redis") public class BarRedisProperties extends RedisProperties{…};
[0075] Then add the following to the application's configuration file: Figure 3 The configuration shown includes host number, port number and other configuration information. spring.data.redis provides an inheritable default configuration, while foo.redis and bar.redis store the configurations that need to be modified according to business requirements.
[0076] Once the application starts, injection can be performed in the business code by specifying the name using the @Qualifier annotation, as shown in the following code:
[0077] @Component
[0078] public class RedisConfiguration {
[0079] @Qualifier("fooRedisProperties")
[0080] private FooRedisProperties fooRedisProperties; / / Inject fooRedis configuration instance by name
[0081] @Qualifier("barRedisProperties ")
[0082] private BarRedisProperties barRedisProperties; / / Inject barRedis configuration instance by name};
[0083] It should be noted that after receiving the data refresh instruction (RefreshEvent), the system will jump to the step of setting the annotations of each target as parameters of the modified method, so as to rebind the key-value pairs corresponding to each target configuration.
[0084] Furthermore, this embodiment can determine the data configuration requirements of each target configuration object in the current application scenario, and set the data processing logic corresponding to the preset inheritance prefix according to the data configuration requirements of each target configuration object; using the configuration management strategy based on Spring Boot corresponding to the data processing logic, it binds each key-value pair in the target framework to the corresponding target configuration object. That is, developers can customize the processing logic of inheritedPrefix according to actual needs to adapt to different configuration inheritance strategies. At the same time, since the solution is based on Spring Boot, it can make full use of the rich resources and support provided by the Spring Boot community.
[0085] Therefore, this application extends annotations in the Spring Boot framework so that when Spring Boot starts and loads configuration, if a target annotation specifies a preset inheritance prefix, the configuration corresponding to that prefix will be read first as the default setting. The configuration corresponding to the original preset prefix in the annotation will then be used as the modified part for specific environments, overriding the default configuration. In this way, this method successfully implements a configuration inheritance mechanism, enabling the generation of configuration object instances that include both default settings and personalized adjustments.
[0086] See Figure 4 As shown, this embodiment of the invention discloses a configuration management device based on Spring Boot, comprising:
[0087] The method modification module 11 is used to find target annotations in the target framework, add a preset inheritance prefix to each target annotation, and modify the initial method corresponding to the configuration property binder in the target framework to obtain the corresponding modified method; wherein, the target framework is the Spring Boot framework;
[0088] The configuration list creation module 12 is used to set each of the target annotations as parameters of the modified method, and to determine whether the preset inheritance prefix has been added to the current target annotation in the modified method. If the preset inheritance prefix has been added to the current target annotation, then a target configuration list is created.
[0089] The prefix replacement module 13 is used to replace the prefix of the key-value pair corresponding to the current configuration item in the target configuration list with the preset inherited prefix if the prefix of the key-value pair matches the preset inherited prefix, so as to obtain the new configuration item corresponding to the current configuration item.
[0090] The data binding module 14 is used to create a target binder based on the target configuration list. If the target framework explicitly defines a preset key value corresponding to the preset original prefix, the key value in the new configuration item is replaced with the preset key value corresponding to the preset original prefix to obtain the corresponding replaced configuration item. The target binder is then used to bind the key value in the replaced configuration item to the target configuration object to achieve the inheritance of configuration by different configuration objects.
[0091] Therefore, this application extends annotations in the Spring Boot framework so that when Spring Boot starts and loads configuration, if a target annotation specifies a preset inheritance prefix, the configuration corresponding to that prefix will be read first as the default setting. The configuration corresponding to the original preset prefix in the annotation will then be used as the modified part for specific environments, overriding the default configuration. In this way, this method successfully implements a configuration inheritance mechanism, enabling the generation of configuration object instances that include both default settings and personalized adjustments.
[0092] In some specific embodiments, the configuration list creation module 12 may specifically include:
[0093] The configuration list creation unit is used to obtain the configuration file list corresponding to each configuration item in the target framework, use the configuration file list as a parameter of a preset construction method, and use the preset construction method and the configuration file list to create the target configuration list.
[0094] In some specific embodiments, the data binding module 14 further includes:
[0095] The resource storage class creation unit is used to place the key-value pairs corresponding to the new configuration item into a preset initial Map object to obtain the corresponding target Map object, and create a target resource storage class based on the target Map object; wherein, the target resource storage class is used to store the key-value pairs corresponding to the new configuration item;
[0096] The priority setting submodule is used to place the target resource storage class at the end of the target configuration list so that the priority of the key-value pair corresponding to the new configuration item in the target resource storage class is lower than the priority of the preset key-value corresponding to the preset original prefix.
[0097] In some specific embodiments, the priority setting submodule includes:
[0098] The location setting unit is used to call the preset addLast method corresponding to the target configuration list, and use the preset addLast method to place the target resource storage class at the end of the target configuration list.
[0099] In some specific embodiments, the Spring Boot-based configuration management device further includes:
[0100] The key-value binding module is used to bind the key-value corresponding to the preset original prefix to the corresponding target configuration object using the configuration attribute binder in the target framework if the preset inheritance prefix is not added to the current target annotation.
[0101] In some specific embodiments, the Spring Boot-based configuration management device further includes:
[0102] The step jump module is used to jump to the step of setting each of the target annotations as parameters of the modified method after obtaining the data refresh instruction, so as to rebind the key values corresponding to each of the target configurations.
[0103] In some specific embodiments, the Spring Boot-based configuration management device further includes:
[0104] The processing logic design module is used to determine the data configuration requirements corresponding to each of the target configuration objects in the current application scenario, and to set the data processing logic corresponding to the preset inheritance prefix according to the data configuration requirements corresponding to each of the target configuration objects;
[0105] The key-value binding unit is used to bind each key-value pair in the target framework to the corresponding target configuration object using the Spring Boot-based configuration management strategy corresponding to the data processing logic.
[0106] Furthermore, embodiments of this application also disclose an electronic device, Figure 5 This is a structural diagram of an electronic device 20 according to an exemplary embodiment. The content of the diagram should not be construed as limiting the scope of this application.
[0107] Figure 5This is a schematic diagram of the structure of an electronic device 20 provided in an embodiment of this application. Specifically, the electronic device 20 may include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 stores a computer program, which is loaded and executed by the processor 21 to implement the relevant steps in the Spring Boot-based configuration management method disclosed in any of the foregoing embodiments. Alternatively, the electronic device 20 in this embodiment may specifically be a computer.
[0108] In this embodiment, the power supply 23 is used to provide operating voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and external devices, and the communication protocol it follows can be any communication protocol applicable to the technical solution of this application, and is not specifically limited here; the input / output interface 25 is used to acquire external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs, and is not specifically limited here.
[0109] In addition, the memory 22, as a carrier for resource storage, can be a read-only memory, random access memory, disk or optical disk, etc. The resources stored thereon can include operating system 221, computer program 222, etc., and the storage method can be temporary storage or permanent storage.
[0110] The operating system 221 is used to manage and control the various hardware devices on the electronic device 20 and the computer program 222, which may be Windows Server, Netware, Unix, Linux, etc. In addition to including a computer program capable of performing the Spring Boot-based configuration management method executed by the electronic device 20 as disclosed in any of the foregoing embodiments, the computer program 222 may further include computer programs capable of performing other specific tasks.
[0111] Furthermore, this application also discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, it implements the aforementioned Spring Boot-based configuration management method. The specific steps of this method can be found in the corresponding content disclosed in the foregoing embodiments, and will not be repeated here.
[0112] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to in the method section.
[0113] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0114] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein can be implemented directly by hardware, a software module executed by a processor, or a combination of both. The software module can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art.
[0115] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0116] The technical solutions provided in this application have been described in detail above. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the methods and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.
Claims
1. A configuration management method based on Spring Boot, characterized in that, include: The target annotation is located in the target framework. A preset inheritance prefix is added to each target annotation. The initial method corresponding to the configuration property binder in the target framework is modified to obtain the corresponding modified method. The target framework is the Spring Boot framework. Each of the target annotations is set as a parameter of the modified method, and it is determined whether the preset inheritance prefix has been added to the current target annotation in the modified method. If the preset inheritance prefix has been added to the current target annotation, a target configuration list is created. If the prefix of the key-value pair corresponding to the current configuration item in the target configuration list matches the preset inherited prefix, then the prefix corresponding to the current configuration item is replaced with the preset original prefix in the target framework to obtain the new configuration item corresponding to the current configuration item. A target binder is created based on the target configuration list. If the target framework explicitly defines a preset key value corresponding to the preset original prefix, the key value in the new configuration item is replaced with the preset key value corresponding to the preset original prefix to obtain the corresponding replaced configuration item. The target binder is then used to bind the key value in the replaced configuration item to the target configuration object to achieve the inheritance of configuration by different configuration objects.
2. The configuration management method based on Spring Boot according to claim 1, characterized in that, The creation of the target configuration list includes: Obtain the configuration file list corresponding to each configuration item in the target framework, use the configuration file list as a parameter of a preset constructor, and use the preset constructor and the configuration file list to create the target configuration list.
3. The configuration management method based on Spring Boot according to claim 1, characterized in that, Before replacing the key value in the new configuration item with the preset key value corresponding to the preset original prefix, the method further includes: The key-value pairs corresponding to the new configuration item are placed into a preset initial Map object to obtain the corresponding target Map object, and a target resource storage class is created based on the target Map object; wherein, the target resource storage class is used to store the key-value pairs corresponding to the new configuration item; The target resource storage class is placed at the end of the target configuration list so that the priority of the key-value pair corresponding to the new configuration item in the target resource storage class is lower than the priority of the preset key-value pair corresponding to the preset original prefix.
4. The configuration management method based on Spring Boot according to claim 3, characterized in that, Placing the target resource storage class at the end of the target configuration list includes: Invoke the preset addLast method corresponding to the target configuration list, and use the preset addLast method to place the target resource storage class at the end of the target configuration list.
5. The configuration management method based on Spring Boot according to claim 1, characterized in that, Also includes: If the preset inheritance prefix is not added to the current target annotation, the key value corresponding to the preset original prefix is bound to the corresponding target configuration object using the configuration attribute binder in the target framework.
6. The configuration management method based on Spring Boot according to claim 1, characterized in that, Also includes: After receiving the data refresh instruction, the process jumps to the step of setting each of the target annotations as parameters of the modified method, so as to rebind the key values corresponding to each of the target configurations.
7. The configuration management method based on Spring Boot according to claim 1, characterized in that, Also includes: Determine the data configuration requirements corresponding to each target configuration object in the current application scenario, and set the data processing logic corresponding to the preset inheritance prefix according to the data configuration requirements corresponding to each target configuration object; The configuration inheritance strategy corresponding to the data processing logic is used to bind each key-value pair in the target framework to the corresponding target configuration object.
8. A configuration management device based on Spring Boot, characterized in that, include: The method modification module is used to find target annotations in the target framework, add a preset inheritance prefix to each target annotation, and modify the initial method corresponding to the configuration property binder in the target framework to obtain the corresponding modified method; wherein, the target framework is the Spring Boot framework; The configuration list creation module is used to set each of the target annotations as parameters of the modified method, and to determine whether the preset inheritance prefix has been added to the current target annotation in the modified method. If the preset inheritance prefix has been added to the current target annotation, then a target configuration list is created. The prefix replacement module is used to replace the prefix of the key-value pair corresponding to the current configuration item in the target configuration list with the preset inherited prefix if the prefix of the key-value pair matches the preset inherited prefix, so as to obtain the new configuration item corresponding to the current configuration item. The data binding module is used to create a target binder based on the target configuration list. If the target framework explicitly defines a preset key value corresponding to the preset original prefix, the key value in the new configuration item is replaced with the preset key value corresponding to the preset original prefix to obtain the corresponding replaced configuration item. The target binder is then used to bind the key value in the replaced configuration item to the target configuration object to achieve the inheritance of configuration by different configuration objects.
9. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor for executing the computer program to implement the Spring Boot-based configuration management method as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, Used to store computer programs, which, when executed by a processor, implement the Spring Boot-based configuration management method as described in any one of claims 1 to 7.
Citation Information
Patent Citations
A data source access method and apparatus based on Spring Boot in different environments
CN109299172A
Database read-write separation method and device based on SopringBot technology
CN116662425A