spring cloud基础知识 ——spring cloud 的注册中心(一)

开发工具idea,开发技术spring cloud

我的学习借鉴了 https://blog.csdn.net/sky786905664/article/details/78995068 

作者 Sky786905664 的一些文章

首先先建一个maven项目,然后把src目录删除掉。

新建完成后新建一个module,是个spring boot的工程:

新建步骤如下:

需要勾选的如红框所示:

我的工程名字是:eureka-server,目录结构如下:

新建成功后依赖如下:

<dependencies>
   <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>

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>

版本号如下:特别是依赖有unkown错误下载不下来的就是这个版本有问题

<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>

启动类上加上 @EnableEurekaServer 注解标明是注册中心

@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {

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

}

配置文件如下:

server.port=8081
eureka.instance.hostname=localhost
#Eureka是为注册中心,是否需要将自己注册到注册中心上(默认为true)
eureka.client.fetch-registry=false
#Erueka是为注册中心,不需要检索服务信息;(表示是否从Eureka Server获取注册信息,默认为true。
eureka.client.register-with-eureka=false
eureka.client.serviceUrl.defaultZone=http://${eureka.instance.hostname}:${server.port}/eure

启动结果:

访问地址:http://localhost:8081/

码云地址:https://gitee.com/hjc2/springcloud.git 

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值