一、EurekaServer—服务注册中心
二、实战
1. 使用IDEA的Spring Assistan创建工程,选择Default,单击next
2.填写项目信息,命名工程名称为eureka_server,单击next
3.选择SpringCloudDisicovery中的Eureka Server,单击next,然后finish完成。
4.创建完后的工程的pom.xml文件自带依赖spring-cloud-starter-netflix-eureka-server 和spring-boot-starter-test如下:
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
5.给EurekaServerApplication主程序添加@EnableEurekaServer注解
@EnableEurekaServer
@SpringBootApplication
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}
}
6.在resources文件夹下创建application.yml文件,内容如下。并删除掉application.properties。
server:
port: 8761
eureka:
instance:
hostname: localhost
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
7.最终项目目录结构如下
8.启动项目,打开浏览器访问:http://localhost:8761 ,界面如下: