Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the methods of efficient configuration management

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "what are the methods of efficient configuration management". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought. Let's study and learn "what are the methods of efficient configuration management"?

Database-based configuration Management of Spring-boot

Good configuration management is the first step in deployment.

What does configuration management do?

In general, the configuration of an application varies greatly between different deployments (pre-release, production environment, development environment, etc.)

These include:

Configuration of databases, Redis, and other back-end services

Key of third-party services, such as storage, push, etc.

Each deployment-specific configuration, such as domain name, etc.

Objectives of configuration management

One benchmark code, multiple deployments, storing configurations in the environment

The configuration file is submitted as it is incorporated into the version control system, resulting in multiple versions of Profile management.

Unified management

If there is no unified management, the configuration needs to be modified in many places, which is easy to cause forgetfulness and increase the cost of learning.

Key (configuration) security

A simple way to determine whether an application correctly excludes configuration from the code is to see whether the application's benchmark code can be open source immediately without worrying about exposing any sensitive information.

The reason for the current scheme of configuration management feasibility Configuration code file code and configuration mixed together, after packaging, can not adapt to multiple deployment environments. Configuration files such as Spring-boot. Profile management, node.js 's .env √ database-based management is very suitable for third-party key configuration, internal configuration is not convenient √ based configuration services such as Spring Cloud Config, nacos and other configuration services √ database-based configuration management

Spring-boot application configuration management solution (optimized version)

Hongmeng official Strategic Cooperation to build HarmonyOS Technology Community

Configure Application.yml

The environment variable for configuring the DB connection overrides the database connection variable of the original Application.yml.

Excerpt from: 12-Factor recommends that you store the configuration of the application in the environment variable (env vars, env). Environment variables can be easily modified between different deployments without moving a single line of code; unlike configuration files, there is little chance of accidentally checking them into the code base; and environment variables are language-and system-independent compared to some traditional mechanisms for solving configuration problems, such as Java's property configuration files.

Hongmeng official Strategic Cooperation to build HarmonyOS Technology Community

Based on database management (jm-settings)

2.1 Design Key-Value table

CREATE TABLE `troomBaseS` (`id` int (11) unsigned NOT NULL AUTO_INCREMENT, `keyword` varchar (255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'keywords, PAY.ALI PAY.MP', `content` text COLLATE utf8mb4_unicode_ci COMMENT' configuration content', `created` bigint (20) DEFAULT NULL, `updated` bigint (20) DEFAULT NULL, `deleted`int (1) DEFAULT '0requests, PRIMARY KEY (`id`) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT=' setting table'

2.2 Spring-boot @ Bean injection

Declare Property

/ * Huawei OBS configuration * @ author keepcleargas * @ version 1.0 Created in 10:56 on 2021-03-23 * / @ Data public class HuaweiObsProperties {public static final String KEY = "huawei.obs"; private String accessKey; private String secretKey; private String endPoint; / * expiration time (minutes) * / private Long duration = 3600L; / * * buckets * / private List buckets @ Data public static final class Bucket {private Integer type; private String bucketName;} @ JsonIgnore public String getBucketNameByType (Integer type) {for (Bucket bucket: buckets) {if (type.equals (bucket.getType () {return bucket.getBucketName ();}} throw new IllegalArgumentException ("Bucket is not fully configured!") ;}}

Bean injection class

/ * HuaweiObsProperties Bean configuration class * @ author keepcleargas * @ version 1.0 Created in 11:01 on 2021-03-23 * / @ Slf4j @ Configuration public class HuaweiObsConfiguration {@ Resource BaseSettingsService baseSettingsService; @ Bean (name = "huaweiObsProperties") public HuaweiObsProperties getHuaweiObsProperties () {HuaweiObsProperties huaweiObsProperties = baseSettingsService.getObjectByKeyword (HuaweiObsProperties.KEY, HuaweiObsProperties.class); return huaweiObsProperties = = null? New HuaweiObsProperties (): huaweiObsProperties;}}

Bean injection usage

@ Slf4j @ Service public class HuaweiObsService {@ Resource HuaweiObsProperties huaweiObsProperties; / / todo call} Open Source address Project name description address jm-settings DB-based configuration management core library https://github.com/jimoos-cn/...huawei-obs jm-settings-based Huawei obs configuration management https://github.com/jimoos-cn/... Thank you for your reading. the above is the content of "what are the methods of efficient configuration management". After the study of this article, I believe you have a deeper understanding of the methods of efficient configuration management. The specific use of the situation also needs to be verified by practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report