当前位置:网站首页>Openfeign service call

Openfeign service call

2022-04-23 22:10:00 Leon_ Jinhai_ Sun

# 1. Service invocation method introduces dependency OpenFeign rely on 
<!--Open Feign rely on -->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
# 2. Add comments to the entry class to open OpenFeign Support 
@SpringBootApplication
@EnableFeignClients
public class Users9999Application {
    public static void main(String[] args) {
        SpringApplication.run(Users9999Application.class, args);
    }
}
# 3. Create a client call interface 
//value Property to specify : Call service name 
@FeignClient("PRODUCTS")
public interface ProductClient {
  
    @GetMapping("/product/findAll") // Write the service call path 
    String findAll();
}
# 4. Use feignClient The client object invokes the service 
// Inject client objects 
@Autowired
private ProductClient productClient;

@GetMapping("/user/findAllFeignClient")
public String findAllFeignClient(){
  log.info(" By using OpenFeign Component invokes goods and services ...");
  String msg = productClient.findAll();
  return msg;
}
# 5. Access and test services 
- http://localhost:9999/user/findAllFeignClient

版权声明
本文为[Leon_ Jinhai_ Sun]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/113/202204232157393447.html