网站链接: element-ui dtcms
当前位置: 首页 > 技术博文  > 技术博文

Eureka

2021/6/7 19:05:21 人评论

(1)EurekaServer #设置端口号 server: port: 8080 #服务注册中心地址 eureka: instance: hostname: 127.0.0.1 prefer-ip-address: true client: service-url: defaultZone: http://127.0.0.1:8080/eureka/ register-with-eureka: false f…

(1)EurekaServer

#设置端口号
server:
  port: 8080
  
#服务注册中心地址
eureka:
  instance:
    hostname: 127.0.0.1
    prefer-ip-address: true
  client:
    service-url:
      defaultZone: http://127.0.0.1:8080/eureka/
    register-with-eureka: false
    fetch-registry: false


@SpringBootApplication
@EnableEurekaServer
public class EurekaApplication {

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

}

(2)EurekaClient

#设置端口号
server: 
 port: 8081

#服务中心的名称
spring: 
  application: 
    name: app-01

#当前服务注册地址
eureka: 
  client: 
    service-url: 
      defaultZone: http://127.0.0.1:8080/eureka/
    register-with-eureka: true
fetch-registry: true
  instance:
   prefer-ip-address: true
   instance-id: ${server.address}:${server.port}
   status-page-url: http://${server.address}:${server.port}


@SpringBootApplication
@EnableEurekaClient
public class Springboot01Application {

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

}


@RestController
public class Action {
    
    @RequestMapping("a")
    public Object method() {
        return " Spring-SpringBoot-SpringCloud ";
    }

}


#设置端口号
server: 
 port: 8082

#服务中心的名称
spring: 
  application: 
    name: app-02

#当前服务注册地址
eureka: 
  client: 
    service-url: 
      defaultZone: http://127.0.0.1:8080/eureka/
    register-with-eureka: true
fetch-registry: true
  instance:
   prefer-ip-address: true
   instance-id: ${server.address}:${server.port}
   status-page-url: http://${server.address}:${server.port}


@SpringBootApplication
@EnableEurekaClient
public class RibbonApplication {

    public static void main(String[] args) {
        SpringApplication.run(RibbonApplication.class, args);
    }
    
    @Bean
    @LoadBalanced
    RestTemplate restTemplate() {
        return new RestTemplate();
    }

}


@RestController
public class Action {
    
    @Autowired
    RestTemplate rest;
    
    @RequestMapping("b")
    public String method() {
        String s = rest.getForObject("http://app-01/a/", String.class);
        System.out.println(s);
        return s;
    }

}
 

相关资讯

    暂无相关的数据...

共有条评论 网友评论

验证码: 看不清楚?