التهيئة
التهيئة المركزية باستخدام Spring Cloud Config
10-15 دقيقة
التهيئة المركزية باستخدام Spring Cloud Config
تُعدّ التهيئة المركزية جانبًا أساسيًا في معماريات الخدمات المصغّرة (microservices). فهي تتيح إدارة تهيئة جميع الخدمات من نقطة مركزية واحدة، مما يسهّل الصيانة ويضمن الاتساق.
1. إعداد خادم Config
1.1 إنشاء مشروع Config Server
curl https://start.spring.io/starter.tgz \
-d dependencies=cloud-config-server \
-d groupId=com.example \
-d artifactId=config-server \
-d name=config-server \
-d description=Config%20Server%20for%20Microservices \
-d packageName=com.example.config \
-d packaging=jar \
-d javaVersion=17 \
-d type=maven-project \
| tar -xzvf -
1.2 تهيئة الخادم
# application.yml
server:
port: 8888
spring:
application:
name: config-server
cloud:
config:
server:
git:
uri: https://github.com/your-org/config-repo
default-label: main
search-paths:
- config/*
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/
1.3 تفعيل خادم Config
@SpringBootApplication
@EnableConfigServer
@EnableDiscoveryClient
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}
التعليقات
التعليقات مدعومة عبر GitHub Discussions
سجّل الدخول باستخدام GitHub للمشاركة في النقاش