Skip to content

Commit addb8e7

Browse files
Working final version of Cloud Config Client and Server with cryptography enabled.
1 parent f4bbe5c commit addb8e7

8 files changed

Lines changed: 166 additions & 12 deletions

File tree

‎spring-cloud-config/client/pom.xml‎

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<parent>
7+
<groupId>com.baeldung.spring.cloud</groupId>
8+
<artifactId>spring-cloud-config</artifactId>
9+
<version>0.0.1-SNAPSHOT</version>
10+
</parent>
11+
<artifactId>client</artifactId>
12+
<packaging>jar</packaging>
13+
14+
<name>client</name>
15+
<description>Demo project for Spring Cloud Config Client</description>
16+
17+
<properties>
18+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
19+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
20+
<java.version>1.8</java.version>
21+
</properties>
22+
23+
<dependencies>
24+
<dependency>
25+
<groupId>org.springframework.cloud</groupId>
26+
<artifactId>spring-cloud-starter-config</artifactId>
27+
</dependency>
28+
<dependency>
29+
<groupId>org.springframework.boot</groupId>
30+
<artifactId>spring-boot-starter-web</artifactId>
31+
</dependency>
32+
33+
<dependency>
34+
<groupId>org.springframework.boot</groupId>
35+
<artifactId>spring-boot-starter-test</artifactId>
36+
<scope>test</scope>
37+
</dependency>
38+
</dependencies>
39+
40+
<dependencyManagement>
41+
<dependencies>
42+
<dependency>
43+
<groupId>org.springframework.cloud</groupId>
44+
<artifactId>spring-cloud-dependencies</artifactId>
45+
<version>Brixton.BUILD-SNAPSHOT</version>
46+
<type>pom</type>
47+
<scope>import</scope>
48+
</dependency>
49+
</dependencies>
50+
</dependencyManagement>
51+
52+
<build>
53+
<plugins>
54+
<plugin>
55+
<groupId>org.springframework.boot</groupId>
56+
<artifactId>spring-boot-maven-plugin</artifactId>
57+
</plugin>
58+
</plugins>
59+
</build>
60+
61+
<repositories>
62+
<repository>
63+
<id>spring-snapshots</id>
64+
<name>Spring Snapshots</name>
65+
<url>https://repo.spring.io/snapshot</url>
66+
<snapshots>
67+
<enabled>true</enabled>
68+
</snapshots>
69+
</repository>
70+
<repository>
71+
<id>spring-milestones</id>
72+
<name>Spring Milestones</name>
73+
<url>https://repo.spring.io/milestone</url>
74+
<snapshots>
75+
<enabled>false</enabled>
76+
</snapshots>
77+
</repository>
78+
</repositories>
79+
80+
</project>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.baeldung.spring.cloud.config.client;
2+
3+
import org.springframework.beans.factory.annotation.Value;
4+
import org.springframework.boot.SpringApplication;
5+
import org.springframework.boot.autoconfigure.SpringBootApplication;
6+
import org.springframework.http.MediaType;
7+
import org.springframework.web.bind.annotation.PathVariable;
8+
import org.springframework.web.bind.annotation.RequestMapping;
9+
import org.springframework.web.bind.annotation.RequestMethod;
10+
import org.springframework.web.bind.annotation.RestController;
11+
12+
@SpringBootApplication
13+
@RestController
14+
public class ConfigClient {
15+
16+
@Value("${user.role}")
17+
private String role;
18+
19+
@Value("${user.password}")
20+
private String password;
21+
22+
public static void main(String[] args) {
23+
SpringApplication.run(ConfigClient.class, args);
24+
}
25+
26+
@RequestMapping(
27+
value = "/whoami/{username}",
28+
method = RequestMethod.GET,
29+
produces = MediaType.TEXT_PLAIN_VALUE
30+
)
31+
public String whoami(@PathVariable("username") String username) {
32+
return String.format("Hello %s! You are a(n) %s and your password is '%s'.\n", username, role, password);
33+
}
34+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
spring.application.name=config-client
2+
spring.profiles.active=development
3+
spring.cloud.config.uri=http://localhost:8888
4+
spring.cloud.config.username=root
5+
spring.cloud.config.password=s3cr3t
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.baeldung.spring.cloud.config.client;
2+
3+
import org.junit.Test;
4+
import org.junit.runner.RunWith;
5+
import org.springframework.boot.test.SpringApplicationConfiguration;
6+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
7+
import org.springframework.test.context.web.WebAppConfiguration;
8+
9+
@RunWith(SpringJUnit4ClassRunner.class)
10+
@SpringApplicationConfiguration(classes = ConfigClient.class)
11+
@WebAppConfiguration
12+
public class ConfigClientTests {
13+
14+
@Test
15+
public void contextLoads() {
16+
}
17+
18+
}

‎spring-cloud-config/pom.xml‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.baeldung.spring.cloud</groupId>
8+
<artifactId>spring-cloud-config</artifactId>
9+
<version>0.0.1-SNAPSHOT</version>
10+
<packaging>pom</packaging>
11+
12+
<modules>
13+
<module>server</module>
14+
<module>client</module>
15+
</modules>
16+
17+
</project>

‎spring-cloud-config/server/pom.xml‎

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,15 @@
33
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
44
<modelVersion>4.0.0</modelVersion>
55

6-
<groupId>com.baeldung.spring.cloud.config</groupId>
6+
<parent>
7+
<groupId>com.baeldung.spring.cloud</groupId>
8+
<artifactId>spring-cloud-config</artifactId>
9+
<version>0.0.1-SNAPSHOT</version>
10+
</parent>
711
<artifactId>server</artifactId>
8-
<version>0.0.1-SNAPSHOT</version>
9-
<packaging>jar</packaging>
1012

1113
<name>server</name>
12-
<description>Demo project for Spring Boot</description>
13-
14-
<parent>
15-
<groupId>org.springframework.boot</groupId>
16-
<artifactId>spring-boot-starter-parent</artifactId>
17-
<version>1.3.7.RELEASE</version>
18-
<relativePath/> <!-- lookup parent from repository -->
19-
</parent>
14+
<description>Demo project for Spring Cloud Config Server</description>
2015

2116
<properties>
2217
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
server.port=8888
22
spring.cloud.config.server.git.uri=${CONFIG_REPO}
3+
spring.cloud.config.server.git.clone-on-start=true
34
security.user.name=root
4-
security.user.password=s3cr3t
5+
security.user.password=s3cr3t
6+
encrypt.key-store.location=classpath:/config-server.jks
7+
encrypt.key-store.password=my-s70r3-s3cr3t
8+
encrypt.key-store.alias=config-server-key
9+
encrypt.key-store.secret=my-k34-s3cr3t
3.75 KB
Binary file not shown.

0 commit comments

Comments
 (0)