premise
The system is installed with jdk1.8 and above, and configure the maven idea (using idea here for demonstration, maven version 3.5, configure Alibaba Cloud Source)
Project construction
Create a new maven project and create the simplest one. The project name is EurekaServerDemo, the package name is random, and the project packaging method is jar.
You can also use the official spring generator, which will create the basic springboot project structure. For demonstration here, it's OK
Modify the pom file, refer to the following, the version recommendation is the same as this article, there are many pitfalls in springboot and cloud versions.
<?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> <groupId>com.hellxz</groupId> <artifactId>EurekaServerDemo</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-netflix-eureka-server</artifactId> <version>1.3.5.RELEASE</version> </dependency> </dependencies> <name>EurekaServerDemo</name> <description>Demo project for Spring Boot</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.9.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Camden.SR3</version> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-config-server</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka-server</artifactId> </dependency> <!--Expose various indicators--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> </dependency> </dependencyManagement> <build> <plugins> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> </build></project>
Create a new main class to start the project
package com.hellxz.EurekaServerDemo;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;/** * @Author : Hellxz * @Description: EurekaServer * @Date : 2018/4/13 16:53 */@EnableEurekaServer@SpringBootApplicationpublic class EurekaServerDemoApplication { public static void main(String[] args) { //Start this springboot application SpringApplication.run(EurekaServerDemoApplication.class,args); }}Create a new application.properties file in the resources directory to configure EurekaServer-related parameters, or you can use a yaml file
#Provide the service port server.port=1111#Domain name that provides the service, you can use localhost or configure hosts to test eureka.instance.hostname=localhost#Close to register yourself with the registry eureka.client.register-with-eureka=false#Close to close the discovery registration service. The registry is only used to maintain the node eureka.client.fetch-registry=false#Configure the url of the registry to provide the service (refer to the above configuration here) eureka.client.serviceUrl.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka/Start this project and test it
test
Because localhost:1111 is configured as the access path, just access it directly after starting the project, as shown in the figure
At this point, the Eureka registration center has been 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.