SpringCloud微服务实战:一、Eureka注册中心服务端

1.项目启动类application.java类名上增加@EnableEurekaServer注解,声明是注册中心 1 import org.springframework.boot.SpringApplication; 2 import org.springframework.boot.autoconfi...
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
  • 发表于 2019-02-13 13:51
  • 阅读 ( 204 )
  • 分类:网络文章

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除