1. 程式人生 > >SpringCloud微服務實戰:一、Eureka註冊中心服務端

SpringCloud微服務實戰:一、Eureka註冊中心服務端

pub man vat mil desc del des cee reg

1.項目啟動類application.java類名上增加@EnableEurekaServer註解,聲明是註冊中心
 1 import org.springframework.boot.SpringApplication;
 2 import org.springframework.boot.autoconfigure.SpringBootApplication;
 3 import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
 4 @SpringBootApplication
 5 @EnableEurekaServer
 6 public class EurekaApplication {
 7  public static void main(String[] args) {
 8  SpringApplication.run(EurekaApplication.class, args);
 9  }
10 }
2.application.yml配置:
 1 #配置註冊中心服務端信息
 2  eureka:
 3  client:
 4  service-url:
 5  defaultZone: http://localhost:8762/eureka/
 6  #配置是否顯示在註冊中心上
 7  register-with-eureka: false
 8  #自我保護機制,開發環境可以關閉,生產環境必須開啟
 9  server:
10  enable-self-preservation: false
11  #配置在註冊中心顯示的名字
12  spring:
13  application:
14  name: eureka
15  #配置服務端口
16  #server:
17  #  port: 8761
3.pom.xml配置:
 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 3  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 4  <modelVersion>4.0.0</modelVersion>
 5 
 6  <groupId>com.kjm</groupId>
 7  <artifactId>eureka</artifactId>
 8  <version>0.0.1-SNAPSHOT</version>
 9  <packaging>jar</packaging>
10 
11  <name>eureka</name>
12  <description>Eureka服務端</description>
13 
14  <parent>
15  <groupId>org.springframework.boot</groupId>
16  <artifactId>spring-boot-starter-parent</artifactId>
17  <version>2.1.0.RELEASE</version>
18  <relativePath/> <!-- lookup parent from repository -->
19  </parent>
20  <properties>
21  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
22  <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
23  <java.version>1.8</java.version>
24  <spring-cloud.version>Greenwich.M3</spring-cloud.version>
25  </properties>
26  <dependencies>
27  <dependency>
28  <groupId>org.springframework.cloud</groupId>
29  <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
30  </dependency>
31  <dependency>
32  <groupId>org.springframework.boot</groupId>
33  <artifactId>spring-boot-starter-test</artifactId>
34  <scope>test</scope>
35  </dependency>
36  </dependencies>
37  <dependencyManagement>
38  <dependencies>
39  <dependency>
40  <groupId>org.springframework.cloud</groupId>
41  <artifactId>spring-cloud-dependencies</artifactId>
42  <version>${spring-cloud.version}</version>
43  <type>pom</type>
44  <scope>import</scope>
45  </dependency>
46  </dependencies>
47  </dependencyManagement>
48  <build>
49  <plugins>
50  <plugin>
51  <groupId>org.springframework.boot</groupId>
52  <artifactId>spring-boot-maven-plugin</artifactId>
53  </plugin>
54  </plugins>
55  </build>
57  <repositories>
58  <repository>
59  <id>spring-milestones</id>
60  <name>Spring Milestones</name>
61  <url>https://repo.spring.io/milestone</url>
62  <snapshots>
63  <enabled>false</enabled>
64  </snapshots>
65  </repository>
66  </repositories>
67 </project>
4.打包:mvn clean install -Dmaven.test.skip=true
5.啟動註冊中心服務端:java -jar eureka-0.0.1-SNAPSHOT.jar

SpringCloud微服務實戰:一、Eureka註冊中心服務端