Step 01 - Part 1 Intro to Limits Microservice And Spring Cloud Config Server
![](https://blogger.googleusercontent.com/img/a/AVvXsEgfEM2Y1O5wTxdR8mlBpSIf454c1_dzUm2Hb83-0chrmTOu2CgOmxlEiRtgVMNlkc9VdpEM9KOhk2Ybi-AHkri3y-HqIsLa30EyjMnFf5_BdvZacJ-1KZLeQaLLCSp5Nqak1YrAUvafpPKWRtsTaPxMLjzt3sacAkiNQjdTkNSQA0kTBqvgeVjKBEct7FM=w646-h420)
In given Above example we have diffrent Envirnmnet and there respecitve environments
Dev Has 1 Environment
QA Has 2 Environment
STAGE has 1 Environment
PROD has 4 Environments
So by given above exmaple we understand like we have Different services Like
CurrencyCalculationService, CurrencyExchangeService, LimitService and
all each of these has diffrent number of environments for each type of Environment(DEV,QA,STAGE,PROD)
So this type of congifuration managing the individually for each application and each environment is very very difficult, thats where centralized configuration comes into the Picture Spring Cloud Config Server
1. Spring Cloud Config server says you can put all the configuration for your application into GIT Repository
2. and It will take care of managing the configuration and providing it to the specific Microservice
Example: if Limit service says i would want the configuration for dev environment for limit service than Spring Cloud Config Server would be able to provide it to it
so here Spring Cloud Config Server would act as the centralizeed microservice configuration application
STEP 1: Creat Project Limit-Service (MicroService)
![](https://blogger.googleusercontent.com/img/a/AVvXsEhXC9p3OM5an4nAnZ2q-WJh6165Z4RAmA346NZJr5iI-7tjjltCtsmNsJHbhZdKw6drS-VdDMe8zfperIho0EjGPeTGY4s3p8avHbZ1xzJ3t2Lqz918PSWFaYjw_S4FdOTQCrBy9lmXxsD2byDTyt4VuV0xeIgj8LJm3aFuktWmXfpvsNhj-6QxJ12Jtc0=w629-h319)
Export this project and Import in your Eclipse
To resolve Given Below error
org.springframework.cloud.commons.ConfigDataMissingEnvironmentPostProcessor$ImportException: No spring.config.import set
Add the Dependancy in Pom.xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
Project Structure
STEP 2: Creat Hard Coded Limit-Service (MicroService)
Our eventual goal with Limit Service is we would want it to connect to the spring Cloud config server
![](https://blogger.googleusercontent.com/img/a/AVvXsEjP5y4N5S4UK2v1ENvVt0N8mU6kNkYn4pggB4G0sicTubrE3eoENK8-qZXMKJDVRjmruvrflvmVvoipeJJhOL4fjq0QpPKo26oG3zl8d1Q_im3PBlkyQLpavEWFwFCOYFGBEpHd18CykTQp3gUymkyP968qx4nzu_f1S4I_2vzjCbLyVc73KHAQrEEbBwo=w588-h314)
for that we need to configure a few values in application.properties and expose a service using the limit service to retrieve those values
spring.application.name=limits-service
As we create more and more microservices we would want to give the applications a name so that we can easily identify them.as we have given above example in application.properties file "limits-service"
also we need to configure server.port property if we are go so on other services as we need to deploye other service into diffrents port
Create Controller Class
@RestControllerpublic class LimitConfigurationController { @GetMapping("/limits")
public LimitConfiguration retrieveLimitsFromConfigurations() { return new LimitConfiguration(1000, 1);
}
Create Pojo Class
public class LimitConfiguration {
private int maximum;
private int minimum;
protected LimitConfiguration() {
}
public LimitConfiguration(int maximum, int minimum) {
super();
this.maximum = maximum;
this.minimum = minimum;
}
public int getMaximum() {
return maximum;
}
public int getMinimum() {
return minimum;
}
}
Run the Application we will recieve hard code value as given below
Comments
Post a Comment