-
Notifications
You must be signed in to change notification settings - Fork 17
/
ChaosConfigServerApplication.java
51 lines (40 loc) · 1.44 KB
/
ChaosConfigServerApplication.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.example.chaos.monkey.shopping.config;
import java.util.HashMap;
import java.util.Map;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.environment.PropertySource;
import org.springframework.cloud.config.server.EnableConfigServer;
import org.springframework.cloud.config.server.environment.EnvironmentRepository;
import org.springframework.context.annotation.Bean;
/**
* @author Ryan Baxter
*/
@EnableConfigServer
@SpringBootApplication
public class ChaosConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ChaosConfigServerApplication.class, args);
}
@Bean
public EnvironmentRepository environmentRepository() {
return new CustomEnvironmentRepositry();
}
}
class CustomEnvironmentRepositry implements EnvironmentRepository {
Map<String, Object> chaos = new HashMap<>();
PropertySource propertySource;
public CustomEnvironmentRepositry() {
this.chaos.put("chaos.monkey.enabled", true);
propertySource = new PropertySource("toys-bestseller-chaos", this.chaos);
}
@Override
public Environment findOne(String application, String profile, String label) {
Environment env = new Environment(application, profile);
if("toys-bestseller".equalsIgnoreCase(application)) {
env.add(propertySource);
}
return env;
}
}