Skip to content

Commit 69965db

Browse files
TehreemNisaadamd1985
authored andcommitted
Spring Cloud Zookeeper (eugenp#1399)
* Spring Cloud Zookeeper * Spring Cloud Zookeeper Updated
1 parent 22dda8c commit 69965db

12 files changed

Lines changed: 329 additions & 0 deletions

File tree

‎spring-cloud/pom.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<module>spring-cloud-bootstrap</module>
1414
<module>spring-cloud-ribbon-client</module>
1515
<module>spring-cloud-rest</module>
16+
<module>spring-cloud-zookeeper</module>
1617
</modules>
1718
<packaging>pom</packaging>
1819

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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+
<parent>
6+
<groupId>com.baeldung.spring.cloud</groupId>
7+
<artifactId>spring-cloud-zookeeper</artifactId>
8+
<version>1.0.0-SNAPSHOT</version>
9+
</parent>
10+
<artifactId>Greeting</artifactId>
11+
<packaging>jar</packaging>
12+
<dependencies>
13+
<dependency>
14+
<groupId>org.springframework.boot</groupId>
15+
<artifactId>spring-boot-starter</artifactId>
16+
<version>1.5.2.RELEASE</version>
17+
</dependency>
18+
<dependency>
19+
<groupId>org.springframework</groupId>
20+
<artifactId>spring-web</artifactId>
21+
<version>4.3.7.RELEASE</version>
22+
</dependency>
23+
<dependency>
24+
<groupId>org.springframework.cloud</groupId>
25+
<artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
26+
<version>1.0.3.RELEASE</version>
27+
</dependency>
28+
<dependency>
29+
<groupId>org.springframework.boot</groupId>
30+
<artifactId>spring-boot-starter-actuator</artifactId>
31+
<version>1.5.2.RELEASE</version>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.springframework.cloud</groupId>
35+
<artifactId>spring-cloud-starter-feign</artifactId>
36+
<version>1.2.5.RELEASE</version>
37+
</dependency>
38+
<dependency>
39+
<groupId>org.springframework.boot</groupId>
40+
<artifactId>spring-boot-starter-thymeleaf</artifactId>
41+
<version>1.5.2.RELEASE</version>
42+
</dependency>
43+
<dependency>
44+
<groupId>junit</groupId>
45+
<artifactId>junit</artifactId>
46+
<version>4.12</version>
47+
<scope>test</scope>
48+
</dependency>
49+
<dependency>
50+
<groupId>org.hamcrest</groupId>
51+
<artifactId>hamcrest-core</artifactId>
52+
<version>1.3</version>
53+
<scope>test</scope>
54+
</dependency>
55+
</dependencies>
56+
57+
<dependencyManagement>
58+
<dependencies>
59+
<dependency>
60+
<groupId>org.springframework.cloud</groupId>
61+
<artifactId>spring-cloud-dependencies</artifactId> <!--changed -->
62+
<version>Brixton.SR7</version> <!--changed -->
63+
<type>pom</type>
64+
<scope>import</scope>
65+
</dependency>
66+
</dependencies>
67+
</dependencyManagement>
68+
69+
<build>
70+
<plugins>
71+
<plugin>
72+
<groupId>org.springframework.boot</groupId>
73+
<artifactId>spring-boot-maven-plugin</artifactId>
74+
</plugin>
75+
</plugins>
76+
</build>
77+
<name>Greeting</name>
78+
</project>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package com.baeldung.spring.cloud.greeting;
7+
8+
import org.springframework.beans.factory.annotation.Autowired;
9+
import org.springframework.boot.SpringApplication;
10+
import org.springframework.boot.autoconfigure.SpringBootApplication;
11+
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
12+
import org.springframework.cloud.netflix.feign.EnableFeignClients;
13+
import org.springframework.stereotype.Controller;
14+
import org.springframework.ui.Model;
15+
import org.springframework.web.bind.annotation.RequestMapping;
16+
import org.springframework.web.bind.annotation.ResponseBody;
17+
import org.springframework.web.bind.annotation.RestController;
18+
19+
@SpringBootApplication
20+
@EnableDiscoveryClient
21+
public class GreetingApplication {
22+
23+
public static void main(String[] args) {
24+
SpringApplication.run(GreetingApplication.class, args);
25+
}
26+
27+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package com.baeldung.spring.cloud.greeting;
7+
8+
import org.springframework.beans.factory.annotation.Autowired;
9+
import org.springframework.cloud.netflix.feign.EnableFeignClients;
10+
import org.springframework.stereotype.Controller;
11+
12+
import org.springframework.ui.Model;
13+
import org.springframework.web.bind.annotation.RequestMapping;
14+
import org.springframework.web.bind.annotation.RequestMethod;
15+
import org.springframework.web.bind.annotation.ResponseBody;
16+
import org.springframework.web.bind.annotation.RestController;
17+
18+
@Controller
19+
public class GreetingController {
20+
21+
@Autowired
22+
private HelloWorldClient helloWorldClient;
23+
24+
@RequestMapping(value = "/get-greeting", method = RequestMethod.GET)
25+
26+
public String greeting(Model model) {
27+
28+
model.addAttribute("greeting", helloWorldClient.HelloWorld());
29+
return "greeting-view";
30+
31+
}
32+
33+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.baeldung.spring.cloud.greeting;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
5+
import org.springframework.cloud.netflix.feign.EnableFeignClients;
6+
import org.springframework.cloud.netflix.feign.FeignClient;
7+
import org.springframework.context.annotation.Configuration;
8+
import org.springframework.http.MediaType;
9+
import org.springframework.web.bind.annotation.RequestBody;
10+
import org.springframework.web.bind.annotation.RequestMapping;
11+
import org.springframework.web.bind.annotation.RequestMethod;
12+
import org.springframework.web.bind.annotation.ResponseBody;
13+
14+
/**
15+
* This class provides operations on the Validation service.
16+
*
17+
* <p>
18+
* When booting up, Spring will try and find a service named "Validation" (see
19+
* the FeignClient below) under the available ZooKeeper instance.
20+
* </p>
21+
*
22+
*/
23+
@Configuration
24+
@EnableFeignClients
25+
@EnableDiscoveryClient
26+
public class HelloWorldClient {
27+
28+
@Autowired
29+
private TheClient theClient;
30+
31+
@FeignClient(name = "HelloWorld")
32+
interface TheClient {
33+
34+
@RequestMapping(path = "/helloworld", method = RequestMethod.GET)
35+
@ResponseBody
36+
String HelloWorld();
37+
}
38+
39+
/**
40+
* Initiate call to Validation.
41+
*
42+
* @param name
43+
* @return the response
44+
*/
45+
public String HelloWorld() {
46+
return theClient.HelloWorld();
47+
}
48+
49+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
spring:
2+
application:
3+
name: Greeting
4+
cloud:
5+
zookeeper:
6+
connect-string: localhost:2181
7+
server:
8+
port: 8083
9+
logging:
10+
level:
11+
org.apache.zookeeper.ClientCnxn: WARN
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>Greeting Page</title>
5+
</head>
6+
<body>
7+
<h2 th:text="${greeting}"/>
8+
</body>
9+
</html>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
<parent>
6+
<groupId>com.baeldung.spring.cloud</groupId>
7+
<artifactId>spring-cloud-zookeeper</artifactId>
8+
<version>1.0.0-SNAPSHOT</version>
9+
</parent>
10+
<artifactId>HelloWorld</artifactId>
11+
<packaging>jar</packaging>
12+
<dependencies>
13+
<dependency>
14+
<groupId>org.springframework.boot</groupId>
15+
<artifactId>spring-boot-starter</artifactId>
16+
<version>1.5.2.RELEASE</version>
17+
</dependency>
18+
<dependency>
19+
<groupId>org.springframework</groupId>
20+
<artifactId>spring-web</artifactId>
21+
<version>4.3.7.RELEASE</version>
22+
</dependency>
23+
<dependency>
24+
<groupId>org.springframework.cloud</groupId>
25+
<artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
26+
<version>1.0.3.RELEASE</version>
27+
</dependency>
28+
</dependencies>
29+
30+
<dependencyManagement>
31+
<dependencies>
32+
<dependency>
33+
<groupId>org.springframework.cloud</groupId>
34+
<artifactId>spring-cloud-dependencies</artifactId> <!--changed -->
35+
<version>Brixton.SR7</version> <!--changed -->
36+
<type>pom</type>
37+
<scope>import</scope>
38+
</dependency>
39+
</dependencies>
40+
</dependencyManagement>
41+
42+
<build>
43+
<plugins>
44+
<plugin>
45+
<groupId>org.springframework.boot</groupId>
46+
<artifactId>spring-boot-maven-plugin</artifactId>
47+
</plugin>
48+
</plugins>
49+
</build>
50+
<name>HelloWorld</name>
51+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package com.baeldung.spring.cloud.helloworld;
7+
8+
import org.springframework.boot.SpringApplication;
9+
import org.springframework.boot.autoconfigure.SpringBootApplication;
10+
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
11+
12+
@SpringBootApplication
13+
@EnableDiscoveryClient
14+
public class HelloWorldApplication {
15+
public static void main(String[] args) {
16+
SpringApplication.run(HelloWorldApplication.class, args);
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package com.baeldung.spring.cloud.helloworld;
7+
8+
import org.springframework.http.MediaType;
9+
import org.springframework.web.bind.annotation.RequestMapping;
10+
import org.springframework.web.bind.annotation.RequestMethod;
11+
import org.springframework.web.bind.annotation.RestController;
12+
13+
@RestController
14+
public class HelloWorldController {
15+
16+
@RequestMapping(path = "/helloworld", method = RequestMethod.GET)
17+
public String HelloWorld() {
18+
return "Hello World!";
19+
}
20+
21+
}

0 commit comments

Comments
 (0)