Eureka Server and Clients

This commit is contained in:
Christian Rädel
2016-08-17 04:45:05 +02:00
parent 21550cd2f8
commit d97a894f51
14 changed files with 363 additions and 0 deletions
@@ -0,0 +1,15 @@
package com.baeldung.spring.cloud.eureka.client;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@EnableEurekaClient
public class EurekaClientApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaClientApplication.class, args);
}
}
@@ -0,0 +1,8 @@
package com.baeldung.spring.cloud.eureka.client;
import org.springframework.web.bind.annotation.RequestMapping;
public interface GreetingController {
@RequestMapping("/greeting")
String greeting();
}
@@ -0,0 +1,22 @@
package com.baeldung.spring.cloud.eureka.client;
import com.netflix.discovery.EurekaClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class GreetingControllerImpl implements GreetingController {
@Autowired
@Lazy
private EurekaClient eurekaClient;
@Value("${spring.application.name}")
private String appName;
@Override
public String greeting() {
return String.format("Hello from '%s'!", eurekaClient.getApplication(appName).getName());
}
}
@@ -0,0 +1,13 @@
spring:
application:
name: spring-cloud-eureka-client
server:
port: 0
eureka:
client:
serviceUrl:
defaultZone: ${EUREKA_URI:http://localhost:8761/eureka}
instance:
preferIpAddress: true