diff --git a/pom.xml b/pom.xml index 46e6ef145f..7797b9a7da 100644 --- a/pom.xml +++ b/pom.xml @@ -83,6 +83,7 @@ spring-spel spring-rest spring-rest-docs + spring-cloud-config spring-security-basic-auth spring-security-custom-permission diff --git a/spring-cloud-config/client/pom.xml b/spring-cloud-config/client/pom.xml new file mode 100644 index 0000000000..0ef4b35581 --- /dev/null +++ b/spring-cloud-config/client/pom.xml @@ -0,0 +1,79 @@ + + + 4.0.0 + + + com.baeldung.spring.cloud + spring-cloud-config + 0.0.1-SNAPSHOT + + client + jar + + client + Demo project for Spring Cloud Config Client + + + UTF-8 + UTF-8 + 1.8 + + + + + org.springframework.cloud + spring-cloud-starter-config + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.cloud + spring-cloud-dependencies + Brixton.BUILD-SNAPSHOT + pom + import + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/snapshot + + true + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + false + + + + diff --git a/spring-cloud-config/client/src/main/java/com/baeldung/spring/cloud/config/client/ConfigClient.java b/spring-cloud-config/client/src/main/java/com/baeldung/spring/cloud/config/client/ConfigClient.java new file mode 100644 index 0000000000..1dd3bbdab0 --- /dev/null +++ b/spring-cloud-config/client/src/main/java/com/baeldung/spring/cloud/config/client/ConfigClient.java @@ -0,0 +1,29 @@ +package com.baeldung.spring.cloud.config.client; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +@SpringBootApplication +@RestController +public class ConfigClient { + @Value("${user.role}") + private String role; + + @Value("${user.password}") + private String password; + + public static void main(String[] args) { + SpringApplication.run(ConfigClient.class, args); + } + + @RequestMapping(value = "/whoami/{username}", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE) + public String whoami(@PathVariable("username") String username) { + return String.format("Hello %s! You are a(n) %s and your password is '%s'.\n", username, role, password); + } +} diff --git a/spring-cloud-config/client/src/main/resources/bootstrap.properties b/spring-cloud-config/client/src/main/resources/bootstrap.properties new file mode 100644 index 0000000000..c9c453fa76 --- /dev/null +++ b/spring-cloud-config/client/src/main/resources/bootstrap.properties @@ -0,0 +1,5 @@ +spring.application.name=config-client +spring.profiles.active=development +spring.cloud.config.uri=http://localhost:8899 +spring.cloud.config.username=root +spring.cloud.config.password=s3cr3t diff --git a/spring-cloud-config/client/src/test/java/com/baeldung/spring/cloud/config/client/ConfigClientTests.java b/spring-cloud-config/client/src/test/java/com/baeldung/spring/cloud/config/client/ConfigClientTests.java new file mode 100644 index 0000000000..fb302beabd --- /dev/null +++ b/spring-cloud-config/client/src/test/java/com/baeldung/spring/cloud/config/client/ConfigClientTests.java @@ -0,0 +1,16 @@ +package com.baeldung.spring.cloud.config.client; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.web.WebAppConfiguration; + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(classes = ConfigClient.class) +@WebAppConfiguration +public class ConfigClientTests { + @Test + public void contextLoads() { + } +} diff --git a/spring-cloud-config/pom.xml b/spring-cloud-config/pom.xml new file mode 100644 index 0000000000..bce1fb3fa4 --- /dev/null +++ b/spring-cloud-config/pom.xml @@ -0,0 +1,21 @@ + + + 4.0.0 + + com.baeldung.spring.cloud + spring-cloud-config + 0.0.1-SNAPSHOT + pom + + + server + client + + + + org.springframework.boot + spring-boot-starter-parent + 1.3.5.RELEASE + + diff --git a/spring-cloud-config/server/pom.xml b/spring-cloud-config/server/pom.xml new file mode 100644 index 0000000000..c3f68854bb --- /dev/null +++ b/spring-cloud-config/server/pom.xml @@ -0,0 +1,82 @@ + + + 4.0.0 + + + com.baeldung.spring.cloud + spring-cloud-config + 0.0.1-SNAPSHOT + + server + + server + Demo project for Spring Cloud Config Server + + + UTF-8 + UTF-8 + 1.8 + + + + + org.springframework.cloud + spring-cloud-config-server + + + org.springframework.boot + spring-boot-starter-security + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.cloud + spring-cloud-dependencies + Brixton.BUILD-SNAPSHOT + pom + import + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/snapshot + + true + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + false + + + + diff --git a/spring-cloud-config/server/src/main/java/com/baeldung/spring/cloud/config/server/ConfigServer.java b/spring-cloud-config/server/src/main/java/com/baeldung/spring/cloud/config/server/ConfigServer.java new file mode 100644 index 0000000000..4dd34ae3ff --- /dev/null +++ b/spring-cloud-config/server/src/main/java/com/baeldung/spring/cloud/config/server/ConfigServer.java @@ -0,0 +1,15 @@ +package com.baeldung.spring.cloud.config.server; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.config.server.EnableConfigServer; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; + +@SpringBootApplication +@EnableConfigServer +@EnableWebSecurity +public class ConfigServer { + public static void main(String[] args) { + SpringApplication.run(ConfigServer.class, args); + } +} diff --git a/spring-cloud-config/server/src/main/resources/application.properties b/spring-cloud-config/server/src/main/resources/application.properties new file mode 100644 index 0000000000..ec324011f8 --- /dev/null +++ b/spring-cloud-config/server/src/main/resources/application.properties @@ -0,0 +1,10 @@ +server.port=8899 +## spring.cloud.config.server.git.uri=https://github.com/slavisa-baeldung/tutorials/tree/pr/christian-cloud-config/spring-cloud-config/versioned-config +spring.cloud.config.server.git.uri=file:///C:/projects/baeldung/tutorials/spring-cloud-config/versioned-config +spring.cloud.config.server.git.clone-on-start=false +security.user.name=root +security.user.password=s3cr3t +encrypt.key-store.location=classpath:/config-server.jks +encrypt.key-store.password=my-s70r3-s3cr3t +encrypt.key-store.alias=config-server-key +encrypt.key-store.secret=my-k34-s3cr3t diff --git a/spring-cloud-config/server/src/main/resources/config-server.jks b/spring-cloud-config/server/src/main/resources/config-server.jks new file mode 100644 index 0000000000..f3dddb4a8f Binary files /dev/null and b/spring-cloud-config/server/src/main/resources/config-server.jks differ diff --git a/spring-cloud-config/server/src/test/java/com/baeldung/spring/cloud/config/server/ConfigServerTests.java b/spring-cloud-config/server/src/test/java/com/baeldung/spring/cloud/config/server/ConfigServerTests.java new file mode 100644 index 0000000000..7bde39615b --- /dev/null +++ b/spring-cloud-config/server/src/test/java/com/baeldung/spring/cloud/config/server/ConfigServerTests.java @@ -0,0 +1,17 @@ +package com.baeldung.spring.cloud.config.server; + +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.web.WebAppConfiguration; + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(classes = ConfigServer.class) +@WebAppConfiguration +public class ConfigServerTests { + @Test + public void contextLoads() { + } +} diff --git a/spring-cloud-config/versioned-config/config-client-development.properties b/spring-cloud-config/versioned-config/config-client-development.properties new file mode 100644 index 0000000000..d96f3ac0c5 --- /dev/null +++ b/spring-cloud-config/versioned-config/config-client-development.properties @@ -0,0 +1 @@ +user.role=Developer \ No newline at end of file diff --git a/spring-cloud-config/versioned-config/config-client-production.properties b/spring-cloud-config/versioned-config/config-client-production.properties new file mode 100644 index 0000000000..b341a9b750 --- /dev/null +++ b/spring-cloud-config/versioned-config/config-client-production.properties @@ -0,0 +1 @@ +user.role=User \ No newline at end of file