Preface
Eureka is a service discovery and registration framework. To be more specific, we can divide it into two types: eureka-server (service discovery) and eureka-client (service registration). This time, we will build a project for eureka-server (service discovery) as the beginning of spring-cloud.
Open source address: https://github.com/bigbeef
Project structure
Everyone should know the structure of maven (if you are not clear, you need to add it, there are countless articles on maven on Baidu). Let’s take a look at the configuration of these key files.
Code writing
cppba-spring-cloud > pom.xml
<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>com.cppba</groupId> <artifactId>cppba-spring-cloud</artifactId> <version>1.0.0</version> <packaging>pom</packaging> <name>${project.artifactId}</name> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.5.RELEASE</version> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <java.version>1.8</java.version> <spring-cloud.version>Dalston.SR2</spring-cloud.version> </properties> <dependencyManagement> <dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring-cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependency> </dependency> </dependencyManagement> <modules> <module>cppba-spring-cloud-eureka-server</module> </modules></project>cppba-spring-cloud-eureka-server > pom.xml
<?xml version="1.0" encoding="UTF-8"?><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>cppba-spring-cloud-eureka-server</artifactId> <packaging>jar</packaging> <name>${project.artifactId}</name> <parent> <groupId>com.cppba</groupId> <artifactId>cppba-spring-cloud</artifactId> <version>1.0.0</version> </parent> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka-server</artifactId> </dependency> </dependencies> <build> <finalName>${project.name}</finalName> <plugins> <!--Packaging executable jar--> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build></project>SpringCloudEurekaServerApplication.java
package com.cppba;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;@EnableEurekaServer@SpringBootApplicationpublic class SpringCloudEurekaServerApplication { public static void main(String[] args) { SpringApplication.run(SpringCloudEurekaServerApplication.class, args); }}application.properties
server.port=8761eureka.instance.hostname=eureka-servereureka.client.registerWithEureka=falseeureka.client.fetchRegistry=falseeureka.client.serviceUrl.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka/The project is completed
Start the project
We start the main method in SpringCloudEurekaServerApplication and access http://127.0.0.1:8761
At this point, the eureka-server (service discovery) project was successfully built
The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.