标签:程序 return 自动 应用 cli 创建 prefix 如何 discount
案例使用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());
}
标签:程序 return 自动 应用 cli 创建 prefix 如何 discount
原文地址:https://blog.51cto.com/janephp/2449289