eureka的基本使用

eureka服务端依赖:

<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>

eureka服务端yml配置:

server:
  port: 1010  #端口
eureka:
  instance:
    hostname: localhost #主机
  client: #客户端配置
    registerWithEureka: false  #EurekaServer自己不要注册到EurekaServer自己 ,只有EurekaClient才注册
    fetchRegistry: false  #EurekaServer不要拉取服务的通信地址列表 ,只有EurekaClient才拉取地址列表
    serviceUrl:  #注册中心的注册地址
      defaultZone: http://localhost:1010/eureka/  #http://${eureka.instance.hostname}:${server.port}/eureka/
  server:
    enable-self-preservation: false #关闭自我保护警告

主启动类上打上注解:

@EnableEurekaServer

eureka客户端依赖:

<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

eureka客户端yml配置:

eureka:
  client:
    serviceUrl: #链接eureka服务端
      defaultZone: http://localhost:8761/eureka/
  instance:
    prefer-ip-address: true # 开启使用IP地址进行注册
    instance-id: 商品服务:${server.port}# 修改实例Id

spring:
  datasource:
    username: root
    password: 111111
    url: jdbc:mysql:///mybatis0806?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC
    driver-class-name: com.mysql.jdbc.Driver
  application: # 指定此服务的应用名称
    name: product-server

server:
  port: 1010 # user服务端口号

mybatis:
  type-aliases-package: cn.wangjiaojiao.domain
  configuration:
    map-underscore-to-camel-case: true

feign:
  hystrix:
    enabled: true #开启熔断支持

整合mybatis和openfeign的依赖:

<dependencies>
        <!--引入Eureka的客户端依赖,不包含springboot-start-web,所以要单独引入-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        <!--引入springboot-start-web依赖,必须引入-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>cn.wangjiaojiao</groupId>
            <artifactId>common-server</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <!-- spring-boot整合mybatis -->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>1.1.1</version>
        </dependency>
        <!-- mysql驱动 -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.38</version>
        </dependency>

        <!--引入OpenFeign依赖-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
        </dependency>
    </dependencies>

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值