Refresh interface, spring Cloud built-in load balancing
new new projcet, up AS Same, AS, AS Down Update:
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);
}
}
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.