微服远程调用feign配置
时间: 2023-11-08 10:03:00 浏览: 95
使用Feign实现微服务间文件传输
使用Feign进行微服务远程调用的配置步骤如下:
1. 在pom.xml文件中添加Feign和其他依赖项:
```
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
... other dependencies ...
</dependencies>
```
2. 在启动类上添加@EnableFeignClients注解来启用Feign客户端:
```
@SpringBootApplication
@EnableFeignClients
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
```
3. 创建一个Feign客户端接口,使用@FeignClient注解来指定要访问的微服务名称:
```
@FeignClient(name = "service-name")
public interface ServiceClient {
@GetMapping("/api/method")
ResponseEntity<String> method();
}
```
4. 注入Feign客户端接口并调用方法:
```
@RestController
public class MyController {
@Autowired
private ServiceClient serviceClient;
@GetMapping("/call-service")
public ResponseEntity<String> callService() {
return serviceClient.method();
}
}
```
阅读全文