微服务学习,搭建注册中心
Eureka:
专门用于给其他服务注册的称为 Eureka Server(服务注册中心),其余注册到 Eureka Server 的服务称为Eureka Client,Eureka的端口号默认为8761
项目结构:
1.1 搭建注册中心
实现服务治理,提供者,消费者都需要在注册中心中进行注册
实现步骤:
1、依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
2、开关类配置
开关类上使用注解:@EnableEurekaServer
//标记这是一个注册中心服务器
@SpringBootApplication
@EnableEurekaServer //标记这是注册中心服务端
public class EurekaApplication {
public static void main(String[] args){
SpringApplication.run(EurekaApplication.class,args); }
}
3、全局配置文件设置
application.yml
4、启动并测试
启动开关类
下一篇文章会介绍如何创建服务者