feature: client server implementation with spring cloud config

This commit is contained in:
RouxAntoine 2023-04-16 15:07:40 +02:00
parent b85a3f2c3a
commit 07f47187f6
Signed by: antoine
GPG Key ID: 098FB66FC0475E70
9 changed files with 86 additions and 54 deletions

View File

@ -11,3 +11,12 @@ test:
run-client:
$(GRADLE_BIN) client:bootRun
run-server:
$(GRADLE_BIN) server:bootRun
curl-server:
curl -s -u "user:b3956c50-2e1e-4426-aaca-6b09f7cc4808" localhost:8090/client/development |jq
curl-client:
curl -s localhost:8080/v1/message

33
build.gradle.kts Normal file
View File

@ -0,0 +1,33 @@
plugins {
java
id("org.springframework.boot") version "3.0.5" apply false
id("io.spring.dependency-management") version "1.1.0" apply false
}
extra["springCloudVersion"] = "2022.0.2"
subprojects {
apply(plugin = "java")
apply(plugin = "org.springframework.boot")
java.sourceCompatibility = JavaVersion.VERSION_17
repositories {
mavenCentral()
}
dependencies {
implementation(
platform("org.springframework.cloud:spring-cloud-dependencies:${property("springCloudVersion")}")
)
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.2")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.2")
}
tasks.getByName<Test>("test") {
useJUnitPlatform()
}
apply(plugin = "io.spring.dependency-management")
}

View File

@ -1,39 +1,10 @@
plugins {
java
id("org.springframework.boot") version "3.0.5"
id("io.spring.dependency-management") version "1.1.0"
}
group = "tk.antoine.roux"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_17
repositories {
mavenCentral()
}
extra["springCloudVersion"] = "2022.0.2"
dependencies {
implementation("org.springframework.cloud:spring-cloud-starter-config")
implementation("org.springframework.boot:spring-boot-starter-actuator")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.cloud:spring-cloud-starter-config")
developmentOnly("org.springframework.boot:spring-boot-devtools")
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.2")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.2")
}
dependencyManagement {
imports {
mavenBom(
"org.springframework.cloud:spring-cloud-dependencies:${property("springCloudVersion")}"
)
}
}
tasks.getByName<Test>("test") {
useJUnitPlatform()
}

View File

@ -0,0 +1,23 @@
package tk.antoine.roux.springcloudconfig.application;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/v1")
public class Endpoint {
private final String message;
public Endpoint(@Value("${application.message}") String message) {
this.message = message;
}
@GetMapping("/message")
public String getMessage() {
return message;
}
}

View File

@ -1 +1,3 @@
spring.application.name=client
spring.profiles.active=development
spring.config.import=configserver:http://user:b3956c50-2e1e-4426-aaca-6b09f7cc4808@localhost:8090

View File

@ -1,29 +1,8 @@
plugins {
java
id("org.springframework.boot") version "3.0.5"
id("io.spring.dependency-management") version "1.1.0"
}
group = "tk.antoine.roux"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_17
repositories {
mavenCentral()
}
extra["springCloudVersion"] = "2022.0.2"
dependencies {
implementation("org.springframework.cloud:spring-cloud-config-server")
implementation("org.springframework.cloud:spring-cloud-starter-config")
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.2")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.2")
}
tasks.getByName<Test>("test") {
useJUnitPlatform()
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-security")
}

View File

@ -0,0 +1 @@
application.message=Hello world

View File

@ -1,5 +1,9 @@
package tk.antoine.roux.springcloudconfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;
@EnableConfigServer
@SpringBootApplication
public class SpringCloudConfigServerApplication {

View File

@ -0,0 +1,10 @@
server.port=8090
spring.profiles.active=native
spring.cloud.config.server.native.search-locations=file:./config-repo/{application}/{profile}
spring.security.user.name=user
spring.security.user.password=b3956c50-2e1e-4426-aaca-6b09f7cc4808
#spring.cloud.config.server.git.uri=file://${user.home}/config-repo
#spring.cloud.config.server.git.search-paths='{application}/{profile}'
#spring.cloud.config.server.git.refresh-rate=10