SpringCloud 微服务

application:

eureka:
  instance:
    #将来注册到该注册中心的微服务包括注册中心都是用ip地址
    prefer-ip-address: true
  client:
    registerWithEureka: true
    fetchRegistry: false
    serviceUrl:
      #注册中心的ip地址
      defaultZone: http://192.168.157.133:8761/eureka/
spring:
  #数据库四要素
  datasource:
    url: jdbc:mysql://localhost/mysql
    password: ps123456
    username: root
    driver-class-name: com.mysql.jdbc.Driver
  application:
    #微服务的名字
    name: userservice
server:
  port: 8882

需要用到的依赖:


    
        org.springframework.cloud
        spring-cloud-starter-eureka
    
    
        mysql
        mysql-connector-java
    
    
        org.mybatis.spring.boot
        mybatis-spring-boot-starter
        1.3.2
    
    
        org.springframework.boot
        spring-boot-starter-data-jpa
    
    
        org.projectlombok
        lombok
        1.16.12
        provided
    


SpringCloud 微服务_第1张图片

调用微服务:
application:

eureka:
  instance:
    #将来注册到该注册中心的微服务包括注册中心都是用ip地址
    prefer-ip-address: true
  client:
    registerWithEureka: true
    fetchRegistry: true
    serviceUrl:
      defaultZone: http://192.168.157.133:8761/eureka/
spring:
  application:
    name: userui
server:
  port: 80

#自定义算法
USERSERVICE:
  ribbon:
    NFLoadBalancerRuleClassName:  cn.ps.rule.Myrule

SpringCloud 微服务_第2张图片

你可能感兴趣的:(SpringCloud 微服务)