[Micro] Ebizal school -SpringCloud create consumer services

Here Insert Picture Description
Refresh interface, spring Cloud built-in load balancing
Here Insert Picture Description
new new projcet, up AS Same, AS, AS Down Update:
Here Insert Picture Description
application.yml

server:
  port: 8764
spring:
  application:
    name: consumer
eureka:
  client:
    service-url:
      defaultZone: http://localhost:8761/eureka/

DemoApplicaiton

package com.huizhi.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;

@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
public class DemoApplication {

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

}

Here Insert Picture Description
Interface:

package com.huizhi.demo.Interface;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;

@FeignClient(name = "provider")
public interface TestInterface {

    @RequestMapping(value = "/test")
    String test();

}

TestController:

package com.huizhi.demo.controller;

import com.huizhi.demo.Interface.TestInterface;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {

    @Autowired
    private TestInterface testInterface;

    @GetMapping("/test")
    public String test(){
        return testInterface.test();
    }
}

run:
find as this,it is correct.
Here Insert Picture Description

Published 268 original articles · won praise 47 · views 30000 +

Guess you like

Origin blog.csdn.net/weixin_39593940/article/details/103829674