Spring Cloud - Users Microservice

목차

Users Microservice

@RestController
@RequestMapping("/")
public class UserController {

@GetMapping("/health_check")
public String status(){
return "It's Working in User Service";
}
}

프로젝트 설정 추가하기

server:
port: 0

spring:
application:
name: user-service

eureka:
instance:
instanceId: ${spring.application.name}:${spring.application.instance_id:${random.value}}
client:
register-with-eureka: true
fetch-registry: true
service-url:
defaultZone: http://localhost:8761/eureka

Application.yml 파일로부터 데이터 가져오기

server:
port: 0

spring:
application:
name: user-service

eureka:
instance:
instanceId: ${spring.application.name}:${spring.application.instance_id:${random.value}}
client:
register-with-eureka: true
fetch-registry: true
service-url:
defaultZone: http://localhost:8761/eureka

greeting:
message: Welcome to the Simple E-commerce.

Enviroment 객체를 사용하는 방법

@RestController
@RequestMapping("/")
public class UserController {
private Environment env;

public UserController(Environment env){
this.env = env;
}

@GetMapping("/health_check")
public String status(){
return "It's Working in User Service";
}

@GetMapping("/welcome")
public String welcome(){
return env.getProperty("greeting.message");
}
}
Share