版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u014270696/article/details/79761371
总的步骤:
- pom文件中添加依赖
- application配置文件配置
- 启动类上添加:@EnableEurekaServer注解
- 测试
下面分步来进行配置:
1,添加依赖:
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
2,application配置文件配置:(这里建议修改文件后缀为.yml格式,能减少代码书写量),这里还是提供两种方式的配置:
NO.1: application.properties
spring.application.name=spring-cloud-eureka
server.port=8001
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
eureka.client.serviceUrl.defaultZone=http://localhost:8001/eureka/
NO2.application.yml
spring:
application:
name: spring-cloud-euraka
server:
port: 8001
eureka:
client:
register-with-eureka: false
fetch-registry: false
serviceUrl:
defaultZone: http://localhost:${server.port}/eureka/
3,启动类添加注解
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@SpringBootApplication
@EnableEurekaServer
public class EurakaApplication {
public static void main(String[] args) {
SpringApplication.run(EurakaApplication.class,args);
}
}
4,测试
项目启动成功后,在浏览器中输入http://localhost:8001 即可访问euraka服务注册中心管理页面。