您好,登錄后才能下訂單哦!
使用Zookeeper作為配置中心,實現配置的修改和自動下發,基于Spriing Cloud我們可以輕松的實現。
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zookeeper-config</artifactId>
</dependency>
server.port=8082
spring.application.name=waiter-service
spring.cloud.zookeeper.connect-string=localhost:2181
eureka.client.service-url.defaultZone=http://****:8761/eureka/
#默認的配置項,訂單折扣率
order.discount=95
/config/應?用名,profile/key=value
1、/config是根目錄
2、服務名是下一級目錄,這里是waiter-service
3、配置的鍵和值對
spring.cloud.zookeeper.config.root=config
spring.cloud.zookeeper.config.default-context=application
spring.cloud.zookeeper.config.profile-separator=','
1、創建根路徑/config
2、創建服務名路徑waiter-service
3、配置一個配置項order.discount = 30
@ConfigurationProperties("order")
@RefreshScope
@Data
@Component
public class OrderProperties {
private Integer discount = 100;
private String waiterPrefix = "test-";
}
@RestController
@RequestMapping("/coffee")
@Slf4j
public class CoffeeController {
@Autowired
private OrderProperties orderProperties;
@PostMapping(path = "/getDiscount")
@ResponseStatus(HttpStatus.CREATED)
public String getDiscount() {
return String.valueOf(orderProperties.getDiscount());
}
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。