Public address: java paradise
Source code: https://gitee.com/hjj520/spring-cloud-2.x
I. Introduction
Spring Cloud Eureka is a service governance module under the Spring Cloud Netflix project. The Spring Cloud Netflix project is one of the subprojects of Spring Cloud. Its main content is the packaging of a series of open source products of Netflix company. It provides self configured Netflix OSS Integration for Spring Boot applications. Through some simple notes, developers can quickly configure common modules in the application and build a huge distributed system. Its main modules include: Eureka, Hystrix, Zuul, and Ribbon.
1. Create a new maven project: SC Eureka server. Its pom.xml configuration is as follows:
<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> <groupId>spring-cloud</groupId> <artifactId>sc-eureka-server</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>sc-eureka-server</name> <url>http://maven.apache.org</url> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.4.RELEASE</version> </parent> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Finchley.RELEASE</version> <type>pom</type> </dependency> </dependencies> </dependencyManagement> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <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-eureka-server</artifactId> <version>1.4.5.RELEASE</version> </dependency> --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> <version>2.0.1.RELEASE</version> </dependency> </dependencies> </project>
Remarks:
Mainly introduce the starter required by eureka server
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> </dependency>
The starter of eureka server before Spring Cloud 1.x is
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka-server</artifactId> <version>1.4.5.RELEASE</version> </dependency>
Spring cloud starter Eureka server has been marked as expired in the central warehouse of http://mvnrepository.com. It is recommended to use spring cloud starter Netflix Eureka server
2. Add the configuration file bootstrap.yml or application.yml
spring: application: name: sc-eureka-server server: port: 5001 eureka: instance: hostname: 127.0.0.1 client: #Since the app is a registry, setting it to false means that it does not register itself with the registry registerWithEureka: false #Since the role of the registry is to maintain the service instance, it does not need to retrieve the service, so it is also set to false frechRegistry: false serviceUrl: defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
Note: you can also use the application-dev.yml configuration file, but add the following configuration: - Dspring.profiles.active=dev
3. Write startup program
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; @SpringBootApplication @EnableEurekaServer public class EurekaServerApplication { public static void main(String[] args) { SpringApplication.run(EurekaServerApplication.class, args); } }
4. Start the program and verify the success
Method 1:
Mode two: