WebConfig Centralized Configuration In Microservices

 POM.xml  :     WebConfig Server : 

--------------------------------------------------------------------------------------------------------------

<properties>

<java.version>1.8</java.version>

<spring-cloud.version>2020.0.3</spring-cloud.version>

</properties>

<dependencies>

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-actuator</artifactId>

</dependency>

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-web</artifactId>

</dependency>

<dependency>

<groupId>org.springframework.cloud</groupId>

<artifactId>spring-cloud-config-server</artifactId>

</dependency>


<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-devtools</artifactId>

<scope>runtime</scope>

<optional>true</optional>

</dependency>

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-test</artifactId>

<scope>test</scope>

</dependency>

</dependencies>

<dependencyManagement>

<dependencies>

<dependency>

<groupId>org.springframework.cloud</groupId>

<artifactId>spring-cloud-dependencies</artifactId>

<version>${spring-cloud.version}</version>

<type>pom</type>

<scope>import</scope>

</dependency>

</dependencies>

</dependencyManagement>


<build>

<plugins>

<plugin>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-maven-plugin</artifactId>

</plugin>

</plugins>

</build>


</project>

------------------------------------------------------------------------------------------------------------


PropertiesFile :

spring.cloud.config.server.git.uri=https://github.com/hexortree/Docker
management.endpoints.web.exposure.exclude=*
server.port=8888
#spring.cloud.config.server.git.default-label=main
spring.application.name=insuranceconfigserver
management.security.enabled=false


-------------------------------------------------------------------------------------------------------------------------


@SpringBootApplication
@EnableConfigServer
public class InsuranceconfigserverApplication {

public static void main(String[] args) {
SpringApplication.run(InsuranceconfigserverApplication.class, args);
}

}

------------------------------------------------------------------------------------------------------------------





Config CLient : Microservice


<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>serviceconfig</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>configclient</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>2021.0.0</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>

-----------------------------------------------------------------------------------------------------------------

Application.Properties

spring.cloud.config.uri=http://localhost:8888
server.port=9001


-------------------------------------------------------------------------------------------------------------------------


@SpringBootApplication
public class ConfigclientApplication {

public static void main(String[] args) {
SpringApplication.run(ConfigclientApplication.class, args);
}

}

--------------------------------------------------------------------------------------------------------------------


@RestController
public class COntroller {


@Value("${name}")
private String name;
@GetMapping("/")
public String getName() {
return name;
}
}

----------------------------------------------------------------------------------------------------------------------



Note : You can use my public repository for practice purpose. I have created One application property in git repo with only one property Name=

I already mentioned name of git repo in properties file.




If Your Microservice name and Properties file name Same On git then Directly hit to That name.

Example :spring.cloud.config.uri=http://localhost:8888
server.port=9001
spring.application.name=configclient


On Git repo I have cretaed 2 properties file 1.application and configclient
so whenver configclient microservice need configurauion data it taken from configclient properties



Comments

Popular posts from this blog

Filter In Javafx

Kotlin with StandAlone Complier