Skip to content

Commit 7e07b0e

Browse files
committed
Merge remote-tracking branch 'upstream/master' into craedel-autovalue-tutorial/build-fix
2 parents b6709ed + 03f1602 commit 7e07b0e

16 files changed

Lines changed: 399 additions & 1 deletion

File tree

‎pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
<module>spring-rest-angular</module>
8888
<module>spring-rest-docs</module>
8989
<module>spring-cloud-config</module>
90-
<module>spring-cloud-eureka</module>
90+
<module>spring-cloud-hystrix</module>
9191

9292
<module>spring-security-basic-auth</module>
9393
<module>spring-security-custom-permission</module>

‎spring-cloud-hystrix/pom.xml‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
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+
<groupId>com.baeldung.spring.cloud</groupId>
7+
<artifactId>spring-cloud-hystrix</artifactId>
8+
<version>1.0.0-SNAPSHOT</version>
9+
<modules>
10+
<module>spring-cloud-hystrix-rest-producer</module>
11+
<module>spring-cloud-hystrix-rest-consumer</module>
12+
<module>spring-cloud-hystrix-feign-rest-consumer</module>
13+
</modules>
14+
<packaging>pom</packaging>
15+
16+
<name>Spring Cloud Hystrix</name>
17+
<description>Spring Cloud Hystrix Demo</description>
18+
19+
<parent>
20+
<groupId>com.baeldung</groupId>
21+
<artifactId>parent-modules</artifactId>
22+
<version>1.0.0-SNAPSHOT</version>
23+
<relativePath>..</relativePath>
24+
</parent>
25+
26+
<properties>
27+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
28+
</properties>
29+
30+
<build>
31+
<pluginManagement>
32+
<plugins>
33+
<plugin>
34+
<groupId>org.apache.maven.plugins</groupId>
35+
<artifactId>maven-compiler-plugin</artifactId>
36+
<version>3.5.1</version>
37+
<configuration>
38+
<source>1.8</source>
39+
<target>1.8</target>
40+
</configuration>
41+
</plugin>
42+
<plugin>
43+
<groupId>org.springframework.boot</groupId>
44+
<artifactId>spring-boot-maven-plugin</artifactId>
45+
<version>1.4.0.RELEASE</version>
46+
</plugin>
47+
</plugins>
48+
</pluginManagement>
49+
</build>
50+
</project>
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
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+
<artifactId>spring-cloud-hystrix-feign-rest-consumer</artifactId>
7+
<version>1.0.0-SNAPSHOT</version>
8+
<packaging>jar</packaging>
9+
10+
<name>Spring Cloud Hystrix Feign REST Consumer</name>
11+
<description>Spring Cloud Hystrix Feign Sample Implementation</description>
12+
13+
<parent>
14+
<groupId>com.baeldung.spring.cloud</groupId>
15+
<artifactId>spring-cloud-hystrix</artifactId>
16+
<version>1.0.0-SNAPSHOT</version>
17+
<relativePath>..</relativePath>
18+
</parent>
19+
20+
<dependencies>
21+
<dependency>
22+
<groupId>com.baeldung.spring.cloud</groupId>
23+
<artifactId>spring-cloud-hystrix-rest-producer</artifactId>
24+
<version>1.0.0-SNAPSHOT</version>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.springframework.cloud</groupId>
28+
<artifactId>spring-cloud-starter-hystrix</artifactId>
29+
<version>1.1.5.RELEASE</version>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.springframework.cloud</groupId>
33+
<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
34+
<version>1.1.5.RELEASE</version>
35+
</dependency>
36+
<dependency>
37+
<groupId>org.springframework.cloud</groupId>
38+
<artifactId>spring-cloud-starter-feign</artifactId>
39+
<version>1.1.5.RELEASE</version>
40+
</dependency>
41+
<dependency>
42+
<groupId>org.springframework.boot</groupId>
43+
<artifactId>spring-boot-starter-web</artifactId>
44+
<version>1.4.0.RELEASE</version>
45+
</dependency>
46+
<dependency>
47+
<groupId>org.springframework.boot</groupId>
48+
<artifactId>spring-boot-starter-thymeleaf</artifactId>
49+
<version>1.4.0.RELEASE</version>
50+
</dependency>
51+
<dependency>
52+
<groupId>org.springframework.boot</groupId>
53+
<artifactId>spring-boot-starter-actuator</artifactId>
54+
<version>1.4.0.RELEASE</version>
55+
</dependency>
56+
</dependencies>
57+
58+
<dependencyManagement>
59+
<dependencies>
60+
<dependency>
61+
<groupId>org.springframework.cloud</groupId>
62+
<artifactId>spring-cloud-starter-parent</artifactId>
63+
<version>Brixton.SR4</version>
64+
<type>pom</type>
65+
<scope>import</scope>
66+
</dependency>
67+
</dependencies>
68+
</dependencyManagement>
69+
70+
<build>
71+
<plugins>
72+
<plugin>
73+
<groupId>org.apache.maven.plugins</groupId>
74+
<artifactId>maven-compiler-plugin</artifactId>
75+
</plugin>
76+
<plugin>
77+
<groupId>org.springframework.boot</groupId>
78+
<artifactId>spring-boot-maven-plugin</artifactId>
79+
</plugin>
80+
</plugins>
81+
</build>
82+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.baeldung.spring.cloud.hystrix.rest.consumer;
2+
3+
import com.baeldung.spring.cloud.hystrix.rest.producer.GreetingController;
4+
import org.springframework.cloud.netflix.feign.FeignClient;
5+
import org.springframework.stereotype.Component;
6+
import org.springframework.web.bind.annotation.PathVariable;
7+
8+
@FeignClient(
9+
name = "rest-producer",
10+
url = "http://localhost:9090",
11+
fallback = GreetingClient.GreetingClientFallback.class
12+
)
13+
public interface GreetingClient extends GreetingController {
14+
@Component
15+
public static class GreetingClientFallback implements GreetingClient {
16+
@Override
17+
public String greeting(@PathVariable("username") String username) {
18+
return "Hello User!";
19+
}
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.baeldung.spring.cloud.hystrix.rest.consumer;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.boot.SpringApplication;
5+
import org.springframework.boot.autoconfigure.SpringBootApplication;
6+
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
7+
import org.springframework.cloud.netflix.feign.EnableFeignClients;
8+
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
9+
import org.springframework.stereotype.Controller;
10+
import org.springframework.ui.Model;
11+
import org.springframework.web.bind.annotation.PathVariable;
12+
import org.springframework.web.bind.annotation.RequestMapping;
13+
14+
@SpringBootApplication
15+
@EnableCircuitBreaker
16+
@EnableHystrixDashboard
17+
@EnableFeignClients
18+
@Controller
19+
public class RestConsumerFeignApplication {
20+
@Autowired
21+
private GreetingClient greetingClient;
22+
23+
public static void main(String[] args) {
24+
SpringApplication.run(RestConsumerFeignApplication.class, args);
25+
}
26+
27+
@RequestMapping("/get-greeting/{username}")
28+
public String getGreeting(Model model, @PathVariable("username") String username) {
29+
model.addAttribute("greeting", greetingClient.greeting(username));
30+
return "greeting-view";
31+
}
32+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
server.port=8082
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!DOCTYPE html>
2+
<html xmlns:th="http://www.thymeleaf.org">
3+
<head>
4+
<title>Greetings from Hystrix</title>
5+
</head>
6+
<body>
7+
<h2 th:text="${greeting}"/>
8+
</body>
9+
</html>
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
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+
<artifactId>spring-cloud-hystrix-rest-consumer</artifactId>
7+
<version>1.0.0-SNAPSHOT</version>
8+
<packaging>jar</packaging>
9+
10+
<name>Spring Cloud Hystrix REST Consumer</name>
11+
<description>Spring Cloud Hystrix Sample Implementation</description>
12+
13+
<parent>
14+
<groupId>com.baeldung.spring.cloud</groupId>
15+
<artifactId>spring-cloud-hystrix</artifactId>
16+
<version>1.0.0-SNAPSHOT</version>
17+
<relativePath>..</relativePath>
18+
</parent>
19+
20+
<dependencies>
21+
<dependency>
22+
<groupId>org.springframework.cloud</groupId>
23+
<artifactId>spring-cloud-starter-hystrix</artifactId>
24+
<version>1.1.5.RELEASE</version>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.springframework.cloud</groupId>
28+
<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
29+
<version>1.1.5.RELEASE</version>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.springframework.boot</groupId>
33+
<artifactId>spring-boot-starter-web</artifactId>
34+
<version>1.4.0.RELEASE</version>
35+
</dependency>
36+
<dependency>
37+
<groupId>org.springframework.boot</groupId>
38+
<artifactId>spring-boot-starter-thymeleaf</artifactId>
39+
<version>1.4.0.RELEASE</version>
40+
</dependency>
41+
<dependency>
42+
<groupId>org.springframework.boot</groupId>
43+
<artifactId>spring-boot-starter-actuator</artifactId>
44+
<version>1.4.0.RELEASE</version>
45+
</dependency>
46+
</dependencies>
47+
48+
<dependencyManagement>
49+
<dependencies>
50+
<dependency>
51+
<groupId>org.springframework.cloud</groupId>
52+
<artifactId>spring-cloud-starter-parent</artifactId>
53+
<version>Brixton.SR4</version>
54+
<type>pom</type>
55+
<scope>import</scope>
56+
</dependency>
57+
</dependencies>
58+
</dependencyManagement>
59+
60+
<build>
61+
<plugins>
62+
<plugin>
63+
<groupId>org.apache.maven.plugins</groupId>
64+
<artifactId>maven-compiler-plugin</artifactId>
65+
</plugin>
66+
<plugin>
67+
<groupId>org.springframework.boot</groupId>
68+
<artifactId>spring-boot-maven-plugin</artifactId>
69+
</plugin>
70+
</plugins>
71+
</build>
72+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.baeldung.spring.cloud.hystrix.rest.consumer;
2+
3+
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
4+
import org.springframework.beans.factory.annotation.Autowired;
5+
import org.springframework.stereotype.Service;
6+
import org.springframework.web.client.RestTemplate;
7+
8+
@Service
9+
public class GreetingService {
10+
@HystrixCommand(fallbackMethod = "defaultGreeting")
11+
public String getGreeting(String username) {
12+
return new RestTemplate().getForObject("http://localhost:9090/greeting/{username}", String.class, username);
13+
}
14+
15+
private String defaultGreeting(String username) {
16+
return "Hello User!";
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.baeldung.spring.cloud.hystrix.rest.consumer;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.boot.SpringApplication;
5+
import org.springframework.boot.autoconfigure.SpringBootApplication;
6+
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
7+
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
8+
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
9+
import org.springframework.stereotype.Controller;
10+
import org.springframework.ui.Model;
11+
import org.springframework.web.bind.annotation.PathVariable;
12+
import org.springframework.web.bind.annotation.RequestMapping;
13+
14+
@SpringBootApplication
15+
@EnableCircuitBreaker
16+
@EnableHystrixDashboard
17+
@Controller
18+
public class RestConsumerApplication {
19+
@Autowired
20+
private GreetingService greetingService;
21+
22+
public static void main(String[] args) {
23+
SpringApplication.run(RestConsumerApplication.class, args);
24+
}
25+
26+
@RequestMapping("/get-greeting/{username}")
27+
public String getGreeting(Model model, @PathVariable("username") String username) {
28+
model.addAttribute("greeting", greetingService.getGreeting(username));
29+
return "greeting-view";
30+
}
31+
}

0 commit comments

Comments
 (0)