文章目录
创建一个springBoot项目
一、springcloud-Eureka服务中心搭建
1、导入依赖
<dependencyManagement>
<dependencies>
<!-- 导入Spring Cloud的依赖管理 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Finchley.SR1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</dependencies>
<!--springboot 整合eureka服务端-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
</dependencies>
2、yml配置文件
server:
port: 8000
#eureka-service
eureka:
instance:
hostname: 127.0.0.1 #注册中心地址
client:
service-Url:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
register-with-eureka: false #是否将自己注册到Eureka服务中,因为该应用本身就是注册中心,不需要再注册自己(集群的时候为true)
fetch-registry: false #是否从Eureka中获取注册信息,因为自己为注册中心,不会在该应用中的检索服务信息
3、启动类上添加注解
//启动此为一个服务注册中心
@EnableEurekaServer
4、启动项目
二、将项目注册进服务中心
新建一个springBoot项目
1.导入依赖
<dependencyManagement>
<dependencies>
<!-- 导入Spring Cloud的依赖管理 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Finchley.SR1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<!--web jar包如果没有的话,项目时启动不成功的-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependencies>
2.yml文件配置
spring:
application:
name: Hello-World
eureka:
client:
service-url:
defaultZone: http://127.0.0.1:8000/eureka/
3.启动类上添加注解
@EnableEurekaClient
4.启动客户端项目
HELLO-WORLD已经注册进来了