Spring Cloud Zookeeper (#1399)

* Spring Cloud Zookeeper

* Spring Cloud Zookeeper Updated
This commit is contained in:
Tehreem
2017-04-07 12:47:33 +05:00
committed by adamd1985
parent 22dda8c2be
commit 69965db187
12 changed files with 329 additions and 0 deletions
@@ -0,0 +1,27 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.baeldung.spring.cloud.greeting;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@EnableDiscoveryClient
public class GreetingApplication {
public static void main(String[] args) {
SpringApplication.run(GreetingApplication.class, args);
}
}
@@ -0,0 +1,33 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.baeldung.spring.cloud.greeting;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
@Controller
public class GreetingController {
@Autowired
private HelloWorldClient helloWorldClient;
@RequestMapping(value = "/get-greeting", method = RequestMethod.GET)
public String greeting(Model model) {
model.addAttribute("greeting", helloWorldClient.HelloWorld());
return "greeting-view";
}
}
@@ -0,0 +1,49 @@
package com.baeldung.spring.cloud.greeting;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* This class provides operations on the Validation service.
*
* <p>
* When booting up, Spring will try and find a service named "Validation" (see
* the FeignClient below) under the available ZooKeeper instance.
* </p>
*
*/
@Configuration
@EnableFeignClients
@EnableDiscoveryClient
public class HelloWorldClient {
@Autowired
private TheClient theClient;
@FeignClient(name = "HelloWorld")
interface TheClient {
@RequestMapping(path = "/helloworld", method = RequestMethod.GET)
@ResponseBody
String HelloWorld();
}
/**
* Initiate call to Validation.
*
* @param name
* @return the response
*/
public String HelloWorld() {
return theClient.HelloWorld();
}
}
@@ -0,0 +1,11 @@
spring:
application:
name: Greeting
cloud:
zookeeper:
connect-string: localhost:2181
server:
port: 8083
logging:
level:
org.apache.zookeeper.ClientCnxn: WARN
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Greeting Page</title>
</head>
<body>
<h2 th:text="${greeting}"/>
</body>
</html>