Skip to content

Commit 1d96bc5

Browse files
committed
BAEL-579 Config Client using Spring Cloud Bus.
1 parent 7845da9 commit 1d96bc5

4 files changed

Lines changed: 39 additions & 33 deletions

File tree

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,26 @@
1515
<dependency>
1616
<groupId>org.springframework.cloud</groupId>
1717
<artifactId>spring-cloud-starter-config</artifactId>
18-
<version>${spring-cloud-starter-config.version}</version>
1918
</dependency>
2019
<dependency>
2120
<groupId>org.springframework.boot</groupId>
2221
<artifactId>spring-boot-starter-web</artifactId>
23-
<version>${org.springframework.boot.version}</version>
2422
</dependency>
2523

2624
<dependency>
2725
<groupId>org.springframework.boot</groupId>
2826
<artifactId>spring-boot-starter-test</artifactId>
29-
<version>${org.springframework.boot.version}</version>
3027
<scope>test</scope>
3128
</dependency>
29+
3230
<dependency>
3331
<groupId>org.springframework.boot</groupId>
3432
<artifactId>spring-boot-actuator</artifactId>
3533
</dependency>
34+
<dependency>
35+
<groupId>org.springframework.cloud</groupId>
36+
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
37+
</dependency>
3638
</dependencies>
3739

3840
<build>
@@ -44,8 +46,4 @@
4446
</plugins>
4547
</build>
4648

47-
<properties>
48-
<spring-cloud-starter-config.version>1.2.2.RELEASE</spring-cloud-starter-config.version>
49-
<org.springframework.boot.version>1.4.2.RELEASE</org.springframework.boot.version>
50-
</properties>
5149
</project>
Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,11 @@
11
package com.baeldung.spring.cloud.config.client;
22

3-
import org.springframework.beans.factory.annotation.Value;
43
import org.springframework.boot.SpringApplication;
54
import org.springframework.boot.autoconfigure.SpringBootApplication;
6-
import org.springframework.cloud.context.config.annotation.RefreshScope;
7-
import org.springframework.http.MediaType;
8-
import org.springframework.web.bind.annotation.PathVariable;
9-
import org.springframework.web.bind.annotation.RequestMapping;
10-
import org.springframework.web.bind.annotation.RequestMethod;
11-
import org.springframework.web.bind.annotation.RestController;
125

136
@SpringBootApplication
14-
@RestController
15-
@RefreshScope
167
public class ConfigClient {
17-
@Value("${user.role}")
18-
private String role;
19-
20-
@Value("${user.password}")
21-
private String password;
22-
238
public static void main(String[] args) {
249
SpringApplication.run(ConfigClient.class, args);
2510
}
26-
27-
@RequestMapping(value = "/whoami/{username}", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE)
28-
public String whoami(@PathVariable("username") String username) {
29-
return String.format("Hello %s! You are a(n) %s and your password is '%s'.\n", username, role, password);
30-
}
3111
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.baeldung.spring.cloud.config.client;
2+
3+
import org.springframework.beans.factory.annotation.Value;
4+
import org.springframework.cloud.context.config.annotation.RefreshScope;
5+
import org.springframework.http.MediaType;
6+
import org.springframework.web.bind.annotation.PathVariable;
7+
import org.springframework.web.bind.annotation.RequestMapping;
8+
import org.springframework.web.bind.annotation.RequestMethod;
9+
import org.springframework.web.bind.annotation.RestController;
10+
11+
@RestController
12+
@RefreshScope
13+
public class ConfigClientController {
14+
@Value("${user.role}")
15+
private String role;
16+
17+
@Value("${user.password}")
18+
private String password;
19+
20+
@RequestMapping(value = "/whoami/{username}", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE)
21+
public String whoami(@PathVariable("username") String username) {
22+
return String.format("Hello %s! You are a(n) %s and your password is '%s'.\n", username, role, password);
23+
}
24+
}
Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
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
6-
spring.cloud.config.fail-fast=true
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
6+
spring.cloud.config.fail-fast=true
7+
spring.rabbitmq.host=localhost
8+
spring.rabbitmq.port=5672
9+
spring.rabbitmq.username=guest
10+
spring.rabbitmq.password=guest

0 commit comments

Comments
 (0)