"Welcome To Ashok IT" "Spring Boot and MicroServices" Topic : Spring API Gateway Date : 04/02/2025 (Session - 118) _____________________________________________________________________________________________________________________________ Config Server ============= * Generally We have several Microservices in project development and each microservice requires some of set of configurations such as database configuration,email configurations,security configuration,application configurations etc., * Suppose if We have 10 microservices in the project definetly we need to duplicate the above configuration for each microservice. * If we are duplicating the configuration of microservices the major problem is that whenever any configuration got changed we need to make necessary changes in all microservices and need to restart or redeployment required. * Inorder to overcome the above problem we got solution as "Config Server". * Config Server is an another simple microservice which will maintains common configurations for all microservices. * Config Server maintains external configuration means common configurations will be stored in Github/Gitlab/Bitbucket. * Inorder to Create the Config Server using spring boot project by adding starter called "config-server". Architecture ============ (Connecting) (Spring Boot) (Connecting) UserService/CustomerService >>>>>>>>>>>>>>>>>> Config Server >>>>>>>>>>>>>>>>>>>>>Github/Gitlab/Bitbucket * Generally Spring cloud config Server collect the configurations in two ways 1) External Configuration i.e., Collecting the configuration from github,gitlab,bitbucket etc., * This kind of configuration mostly will be used for production environment. 2) Native Configuration i.e., Collecting the configuration from local system * This kind of configuration mostly will be used of Development environment. Steps For Developing Config Server Application ============================================== 1) Create the Spring boot Project with below Starter * Config Server 2) Add the below annotation on top of our Spring Boot Main Class @EnableConfigServer 3) Below entries are required in application.properties #github repoistory link spring.cloud.config.server.git.uri=https://github.com/maheshashokit/MicroServices-Configuration #github repository cloning during application startup spring.cloud.config.server.git.clone-on-start=true #Default PortNo for ConfigServer is 8888 server.port=8888 #Setting the active Profile spring.profiles.active=prod 4) After Starting the Spring Boot Application hit below url in your favourite browser http://localhost:8888/application/prod >>>>>>>>>>>>>>>>> active profile OUTPUT ====== // 20231017070826 // http://localhost:8888/application/prod { "name": "application", "profiles": [ "prod" ], "label": null, "version": "35b67ad34e5159a55f85b999666617d070ebe5eb", "state": null, "propertySources": [ { "name": "https://github.com/maheshashokit/MicroServices-Configuration/application-prod.properties", "source": { "spring.datasource.driver-class-name": "oracle.jdbc.driver.OracleDriver", "spring.datasource.url": "jdbc:oracle:thin:@localhost:1521:xe", "spring.datasource.username": "system", "spring.datasource.password": "manager", "spring.jpa.hibernate.ddl-auto": "update", "spring.jpa.show-sql": "true", "welcome.message": "Welcome To AshokIT Production Branch...." } }, { "name": "https://github.com/maheshashokit/MicroServices-Configuration/application.properties", "source": { "spring.datasource.driver-class-name": "oracle.jdbc.driver.OracleDriver", "spring.datasource.url": "jdbc:oracle:thin:@localhost:1521:xe", "spring.datasource.username": "system", "spring.datasource.password": "manager", "spring.jpa.hibernate.ddl-auto": "update", "spring.jpa.show-sql": "true", "welcome.message": "Welcome To AshokIT...." } } ] } Steps for Developing the Config Client Applications =================================================== 1) Take the Existing the Microservices either Customer-Service (or) Address-Service 2) Add the below changes in application.properties #Database Configuration #spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver #spring.datasource.url=jdbc:oracle:thin:@localhost:1521:xe #spring.datasource.username=system #spring.datasource.password=manager #Hibernate Configuration #spring.jpa.hibernate.ddl-auto=update #spring.jpa.show-sql=true #To get connected with config server MS from current microservices #Always gets the details from config server which is running on port of 8888 spring.config.import=optional:configserver: 3) Start the Service-Discovery Application & Customer-Service Application and observe the logs whether configuration is collected from config server or not. 4) Test Some API Resources from Customer-Service in PostMan tool to feel that configuration are inherited or not. NOTE ==== * By default spring cloud config server runs on 8888 port number only. * We can change the port number as per programmer conviences, so we changed to 8572 to cloud config server * When we change the port number make sure config client application need to specify config server url as below in customer-service #Always gets the details from config server which is running on port of 8572 spring.config.import=optional:configserver:http://localhost:8572