学习笔记:微服务-2.spring cloud Eureka server 注册中心搭建

学习spring cloud 首先搭个Eureka server 注册中心,接下来才能创建管理的微服务客户

1.在eclipse-》新建-》其它-》spring boot project

创建一个名为 Eureka-Server的maven项目

2.修改 pom.xml


 
 
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0"
  3. xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  5. <modelVersion>4.0.0 </modelVersion>
  6. <parent>
  7. <groupId>org.springframework.boot </groupId>
  8. <artifactId>spring-boot-starter-parent </artifactId>
  9. <version>2.1.1.RELEASE </version>
  10. <relativePath /> <!-- lookup parent from repository -->
  11. </parent>
  12. <groupId>com.linbin </groupId>
  13. <artifactId>Eureka-Server </artifactId>
  14. <version>0.0.1-SNAPSHOT </version>
  15. <name>Eureka-Server </name>
  16. <description>Demo project for Spring Boot </description>
  17. <properties>
  18. <project.build.sourceEncoding>UTF-8 </project.build.sourceEncoding>
  19. <project.reporting.outputEncoding>UTF-8 </project.reporting.outputEncoding>
  20. <java.version>1.8 </java.version>
  21. <spring-cloud.version>Greenwich.M3 </spring-cloud.version> <!-- Finchley.M8 -->
  22. </properties>
  23. <dependencies>
  24. <dependency>
  25. <groupId>org.springframework.boot </groupId>
  26. <artifactId>spring-boot-starter </artifactId>
  27. </dependency>
  28. <dependency>
  29. <groupId>org.springframework.cloud </groupId>
  30. <artifactId>spring-cloud-starter-config </artifactId>
  31. </dependency>
  32. <dependency>
  33. <groupId>org.springframework.cloud </groupId>
  34. <artifactId>spring-cloud-starter-netflix-eureka-server </artifactId>
  35. </dependency>
  36. <dependency>
  37. <groupId>commons-configuration </groupId>
  38. <artifactId>commons-configuration </artifactId>
  39. <version>1.9 </version>
  40. </dependency>
  41. <dependency>
  42. <groupId>org.springframework.boot </groupId>
  43. <artifactId>spring-boot-starter-test </artifactId>
  44. <scope>test </scope>
  45. </dependency>
  46. </dependencies>
  47. <dependencyManagement>
  48. <dependencies>
  49. <dependency>
  50. <groupId>org.springframework.cloud </groupId>
  51. <artifactId>spring-cloud-dependencies </artifactId>
  52. <version>${spring-cloud.version} </version>
  53. <type>pom </type>
  54. <scope>import </scope>
  55. </dependency>
  56. </dependencies>
  57. </dependencyManagement>
  58. <build>
  59. <plugins>
  60. <plugin>
  61. <groupId>org.springframework.boot </groupId>
  62. <artifactId>spring-boot-maven-plugin </artifactId>
  63. </plugin>
  64. </plugins>
  65. </build>
  66. <repositories>
  67. <repository>
  68. <id>spring-milestones </id>
  69. <name>Spring Milestones </name>
  70. <url>https://repo.spring.io/milestone </url>
  71. <snapshots>
  72. <enabled>false </enabled>
  73. </snapshots>
  74. </repository>
  75. </repositories>
  76. </project>

特别注意 spring boot版本和spring cloud版本的匹配,我这里spring boot=2.1.1,spring cloud=GreenWich.M3 ,不然可能会出错。

3. 修改resources/application.properties 配置文件

server.port=8888
eureka.instance.hostname=centos7
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
eureka.client.serviceUrl.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka/

4. 修改EurekaServerApplication.java

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@EnableEurekaServer
@SpringBootApplication
public class EurekaServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(EurekaServerApplication.class, args);
    }

}

5. 运行测试

eclipse ->运行-》运行方式-》Spring Boot App

微服务注册中心已搭建好了,下节搭建几个测试注册管理的微服务

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值