(一)创建项目
(二)开发服务
1.启动类
package com.example.eurekaservice;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@SpringBootApplication
@EnableDiscoveryClient
public class EurekaServiceApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServiceApplication.class, args);
}
}
2.配置文件 application.yml
spring:
application:
name: eureka-service
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka
3.开发控制层
package com.example.eurekaservice.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@RequestMapping("/hello")
public String hello() {
return "success";
}
}
(三)大功告成
启动项目,浏览器访问:http://localhost:8761/