Feign简介

Feign是Netflix开发的声明式,模板化的HTTP客户端.

  • FeignClientsConfiguration 配置文件
1
2
3
4
5
6
7
@FeignClient( "aidijing-user-service" )
public interface UserFeignClient {

@GetMapping( "api/users/{id}" )
User get ( @PathVariable("id") Long id );

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
@RestController
@RequestMapping( "users" )
public class IndexController {

@Autowired
private UserFeignClient userFeignClient;

@GetMapping( "{id}" )
public User get ( @PathVariable Long id ) {
return userFeignClient.get( id );
}


}
1
2
3
4
5
6
7
8
9
10
11
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
public class AidijingEurekaClientApplication extends SpringBootServletInitializer {
public static void main ( String[] args ) {
SpringApplication.run( AidijingEurekaClientApplication.class, args );
}
protected SpringApplicationBuilder configure ( SpringApplicationBuilder application ) {
return application.sources( AidijingEurekaClientApplication.class );
}
}

.