Skip to content

Instantly share code, notes, and snippets.

@asvignesh
Created March 22, 2020 14:52
Show Gist options
  • Save asvignesh/633025984041ff7748181a9a935f7bad to your computer and use it in GitHub Desktop.
Save asvignesh/633025984041ff7748181a9a935f7bad to your computer and use it in GitHub Desktop.
Spring Boot Config Client
spring.cloud.config.uri=http://localhost:7777
spring.application.name=test
spring.profiles.active=dev
plugins {
id 'org.springframework.boot' version '2.2.5.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
}
group 'io.cloud-odo'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
ext {
set('springCloudVersion', "Hoxton.SR3")
}
dependencies {
implementation 'org.springframework.cloud:spring-cloud-starter-config'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
test {
useJUnitPlatform()
}
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@Component
public class ClientBean {
@Value("${k1}")
private String k1;
public String getK1() {
return k1;
}
@PostConstruct
public void postConstruct() {
System.out.println(k1);
}
}
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class ConfigClientApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigClientApplication.class, args);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment