1.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><groupId>com.eureka</groupId><artifactId>cloud-eureka-server</artifactId><version>0.0.1-SNAPSHOT</version><packaging>jar</packaging><name>cloud-eureka-server</name><description>Demo project for Spring Boot</description><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.1.0.RELEASE</version><relativePath/> <!-- lookup parent from repository --></parent><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><java.version>1.8</java.version><spring-cloud.version>Greenwich.M3</spring-cloud.version></properties><dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-client</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-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><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build><repositories><repository><id>maven-ali</id><url>http://maven.aliyun.com/nexus/content/groups/public/</url></repository><repository><id>spring-milestones</id><name>Spring Milestones</name><url>https://repo.spring.io/milestone</url><snapshots><enabled>false</enabled></snapshots></repository></repositories><pluginRepositories><pluginRepository><id>aliyun-nexus</id><name>aliyun-nexus</name><url>http://maven.aliyun.com/nexus/content/groups/public</url><snapshots><enabled>true</enabled></snapshots><releases><enabled>false</enabled></releases></pluginRepository></pluginRepositories></project>
2.application
package com.eureka;import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;@EnableEurekaServer //开启EurekaServer @SpringBootApplication public class EurekaServerApplication {public static void main(String[] args) {SpringApplication.run(EurekaServerApplication.class, args);} }
2.application.yml ,
springboot 版本为2,和1,不一样
server:port: 8761spring:application:name: spring-cloud-eureka-server-1 eureka:client:#表示是否将自己注册到Eureka Server,默认为true。registerWithEureka: true#表示是否从Eureka Server获取注册信息,默认为true。fetchRegistry: falseserver:waitTimeInMsWhenSyncEmpty: 0#设置与Eureka Server交互的地址,查询服务和注册服务都需要依赖这个#serviceUrl:#defaultZone: ${vcap.services.eureka-service.credentials.uri:http://127.0.0.1:8762}/eureka/
4.此处自己注册自己注册成功