1.pom引入依赖
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-consul-discovery</artifactId> </dependency>
2.修改yml配置文件
spring: application: name: cloud-order-service cloud: consul: host: localhost port: 8500 discovery: service-name: ${spring.application.name}
3.启动类加 @EnableDiscoveryClient 注解
@SpringBootApplication @EnableDiscoveryClient public class OrderConsulMain80 { public static void main(String[] args) { SpringApplication.run(OrderConsulMain80.class, args); } }