Spring Cloud Config
λΆμ° μμ€ν
νκ²½μμ μ ν리μΌμ΄μ
μ€μ μ μ€μμμ κ΄λ¦¬νλ κ΅¬μ± κ΄λ¦¬ μλ²
μ μ¬μ©νλμ§
ν΄κ²°νλ λ¬Έμ
μ€μ νμΌμ μ μ₯νκ³ μ 곡νλ μλ² μν μν
μ€μ μ μ₯μ μν λ΄λΉ
@SpringBootApplication
@EnableConfigServer
public class ConfigApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigApplication.class, args);
}
}
κ° μλΉμ€λ Config Serverμμ μ€μ μ κ°μ Έμμ μ¬μ©
spring:
application:
name: product-service
config:
import: "configserver:"
cloud:
config:
discovery:
enabled: true
service-id: config-server
νκ²½λ³ μ€μ νμΌ λΆλ¦¬ κ°λ₯
product-service.yml
product-service-local.yml
product-service-dev.yml
product-service-qa.yml
product-service-prod.yml
spring:
profiles:
active: local
β» νλ‘ν μ΄λ¦μ κ³ μ κ·μΉμ΄ μλ ν μ μ±
μ λ°λΌ ꡬμ±
(local, dev, qa, staging, prod λ±)
μ€μ λ³κ²½ ν λ°μ λ°©μ
μ΄λ² ꡬμ±μμλ μλ κ°±μ λ°©μ μ¬μ©
Client Service β Eureka β Config Server β μ€μ νμΌ μ‘°ν β Client μ μ©
μ€ν νλ¦
Product Service μ€ν
β Eureka λ±λ‘
β Config Server μμΉ μ‘°ν
β product-service-local.yml λ‘λ
β μ€μ μ μ©
μ€μ λ³κ²½ νλ¦
μ€μ νμΌ μμ
β Config Server λ°μ
β /actuator/refresh νΈμΆ
β μ€μ μ¬μ μ©
ꡬ쑰
Eureka Server β Config Server β Product Service
server:
port: 18080
spring:
profiles:
active: native
application:
name: config-server
cloud:
config:
server:
native:
search-locations: classpath:/config-repo
eureka:
client:
service-url:
defaultZone: http://localhost:19090/eureka/
server:
port: 0
spring:
profiles:
active: local
application:
name: product-service
config:
import: "configserver:"
cloud:
config:
discovery:
enabled: true
service-id: config-server
management:
endpoints:
web:
exposure:
include: refresh
eureka:
client:
service-url:
defaultZone: http://localhost:19090/eureka/
# product-service.yml
server:
port: 19093
message: "product-service message"
# product-service-local.yml
server:
port: 19083
message: "product-service-local message"
@RefreshScope
@RestController
@RequestMapping("/product")
public class ProductController {
@Value("${server.port}")
private String serverPort;
@Value("${message}")
private String message;
@GetMapping
public String getProduct() {
return "Product detail from PORT : " + serverPort + " and message : " + message;
}
}
Spring Cloud Config μ¬μ© μ μ€μ μ€μ κ΄λ¦¬ κ°λ₯
application name + profile κΈ°μ€μΌλ‘ νκ²½λ³ μ€μ λΆλ¦¬
native λͺ¨λλ‘ λ‘컬 νκ²½ κ΅¬μ± κ°λ₯
/actuator/refresh νΈμΆλ‘ μλ μ€μ κ°±μ μ²λ¦¬
νλ‘ν μ΄λ¦μ ν μ μ±
μ λ°λΌ μμ λ‘κ² κ΅¬μ± κ°λ₯