微服务笔记(一) 搭建服务治理中心

参考《SpringCloud 微服务和分布式系统实践》学习
服务治理中心是微服务(分布式)架构中最基础和最核心的功能组件,它主要对各个服务实例进行管理,包括服务注册和服务发现等。

搭建服务治理中心


集成Eureka

  1. 首先新建一个module,并添加web和eureka依赖
<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
  1. 添加注解
@SpringBootApplication
//驱动服务治理中心
@EnableEurekaServer
public class EurekaApplication {

    public static void main(String[] args) {
        SpringApplication.run(EurekaApplication.class, args);
    }
  1. 配置yml文件
spring:
  application:
    name: eureka

server:
  port: 8001

eureka:
  client:
    # 取消注册自身,否则会一直报错
    register-with-eureka: false
    # 取消服务获取
    fetch-registry: false
    # 服务注册域地址
#    service-url:
#      defaultZone: http:192.168.1.100:8002/eureka
  instance:
    # 服务治理中心服务器IP
    hostname: 192.168.1.100
  1. 启动项目,打开localhost:8001

  2. 注意事项
    如果选择JDK 8(不含)以上的版本,可能会启动失败,这是因为SpringCloud的Netflix组件是依赖于JDK 8(含)之前的版本开发的,所以在新的JDK版本中会缺少一些包,因此我们需要引入新的依赖才能正常启动Eureka服务器,代码如下:

<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.3.0</version>
</dependency>
<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-impl</artifactId>
    <version>2.3.0</version>
</dependency>
<dependency>
    <groupId>org.glassfish.jaxb</groupId>
    <artifactId>jaxb-runtime</artifactId>
    <version>2.3.0</version>
</dependency>
<dependency>
    <groupId>javax.activation</groupId>
    <artifactId>activation</artifactId>
    <version>1.1.1</version>
</dependency>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值