1.项目介绍
SpringCloud EurekaServer的搭建可以说是很简单的了, 我们只需要引入spring-cloud-starter-netflix-eureka-server
包, 然后再启动类上加上 @EnableEurekaServer
即可
2.项目搭建
- 引入jar包
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>yang-register</artifactId>
<version>${yang-register.version}</version>
<packaging>jar</packaging>
<name>yang-register</name>
<parent>
<groupId>cn.codeyang</groupId>
<artifactId>yang-cloud</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath/>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
- 在启动类上添加注解
@SpringBootApplication
@EnableEurekaServer
public class YangRegisterApplication {
public static void main(String[] args) {
SpringApplication.run(YangRegisterApplication.class, args);
}
}
- 添加配置文件
bootstrap.yml
server:
port: 8761
spring:
application:
name: yang-register
profiles:
active: dev
application-dev.yml
eureka:
client:
service-url:
defaultZone: http://localhost:${server.port}/eureka/
fetch-registry: false
register-with-eureka: false
registry-fetch-interval-seconds: 10
instance-info-replication-interval-seconds: 10
项目到这里就已经OK了,然后启动项目并访问http://localhost:8761