1.創建一個名稱爲eureka-service的springboot項目後在properties加入相關配置
#服務名稱
spring.application.name=eureka-service
#端口號
server.port=8762
#在註冊中心中進行註冊
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/
#啓動服務發現的功能,開啓了才能調用其它服務
#spring.cloud.config.discovery.enabled=true
#發現的服務的名字--對應注測中心的服務名字
#spring.cloud.config.discovery.serviceId=eurka-server
2.添加provider需要的pom文件
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
3.在SpringBoot的啓動類上加上@EnableEurekaClient註解
@SpringBootApplication
@EnableEurekaClient
public class EurekaServiceApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServiceApplication.class, args);
}
}
4.啓動eureka-service項目後刷新註冊中心界面,就會發現eureka-service已經註冊到註冊中心了
5.寫一個接口調用,模擬一下
@RestController
public class demoController {
@RequestMapping(value = "find",method = RequestMethod.GET)
public String findInfo(){
return "service";
}
}
6.在瀏覽器輸入http://localhost:8762/find