第一步:导入依赖
<!-- consul-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
</dependency>
第二部:编写yml配置文件
server:
port: 8004
spring:
application:
name: consul-provider-payment
cloud:
consul:
port: 8500
host: localhost
discovery:
service-name: ${spring.application.name}
第三步:在启动类上加上注解@EnableDiscoveryClient
第四步:编写测试controller
@RestController
@RequestMapping(value = "payment")
public class PaymentController {
@Value("${server.port}")
private String serverPort;
@RequestMapping(value = "/zk")
public String payment(){
return "spring with consumer : " + serverPort + "\t" + UUID.randomUUID().toString();
}
}
第五步:启动程序,浏览器输入localhost:8500 ,成功进入页面表示正确
标签:name,springcloud,consul,配置,payment,spring,port,cloud From: https://www.cnblogs.com/huoziqi/p/17532070.html