所讲代码仓库地址:https://gitee.com/raoyuuuu/springcloud-demo
eureka-server的创建相对简单,步骤如下
- 创建工程
- 导入eureka依赖
- application配置eureka相关配置
- 启动类上注解开启eureka
org.springframework.cloud spring-cloud-starter-netflix-eureka-server
完整
application配置4.0.0 com.example cloud-parent 0.0.1-SNAPSHOT com.example cloud-eureka 0.0.1-SNAPSHOT cloud-eureka Demo project for Spring Boot 1.8 org.springframework.boot spring-boot-starter org.springframework.boot spring-boot-starter-test test org.springframework.cloud spring-cloud-starter-netflix-eureka-server org.springframework.boot spring-boot-maven-plugin
server:
port: 7001
# eureka配置
eureka:
instance:
hostname: localhost # eureka服务端的实例名称
client:
register-with-eureka: false # 是否向eureka注册自己,因为这里为eureka服务端,所以设置false
fetch-registry: false # false 表示自己为注册中心
service-url:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
启动类开启eureka服务
@EnableEurekaServer
@SpringBootApplication
public class CloudEurekaApplication {
public static void main(String[] args) {
SpringApplication.run(CloudEurekaApplication.class, args);
}
}
启动服务,访问 http://localhost:7001/



