高可用ribbon负载均衡业务整合

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/shenzhen_zsw/article/details/89178628

高可用ribbon负载均衡业务整合

创建2个工程

工程1

application.properties

server.port=8081
spring.application.name=youfanproducttype
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/

工程2

application.properties

server.port=8011
spring.application.name=youfanproducttype
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/

产品类型控制器

package com.youfan.control;


import com.youfan.model.ProductType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * Created by youfan on 2018/6/6 0006.
 */
@RestController
public class ProducttypoutControl {
    /**
     * 注入RestTemplate
     */
    @Autowired
    RestTemplate restTemplate;

    @RequestMapping(value = "/listproducttype",method = RequestMethod.GET)
    public List<ProductType> listproducttype(){
        String url="http://YOUFANPRODUCTTYPE/listproducttype";
        List<ProductType> list = restTemplate.getForObject(url,List.class);
        return list;
    }

}

说明:

1)通过YOUFANPRODUCTTYPE可以访问对应的实例服务;

猜你喜欢

转载自blog.csdn.net/shenzhen_zsw/article/details/89178628