Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/moyada/feign-help
a simple plugin for automatic create feign fallback factory.
https://github.com/moyada/feign-help
feign feign-client java-annotation-processor maven spring
Last synced: 2 days ago
JSON representation
a simple plugin for automatic create feign fallback factory.
- Host: GitHub
- URL: https://github.com/moyada/feign-help
- Owner: moyada
- License: apache-2.0
- Created: 2021-08-17T16:00:06.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2021-11-12T14:15:07.000Z (almost 3 years ago)
- Last Synced: 2024-10-11T20:42:58.097Z (27 days ago)
- Topics: feign, feign-client, java-annotation-processor, maven, spring
- Language: Java
- Homepage:
- Size: 160 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Feign Help
针对 `Spring-Feign` 开发环境下,编译生成二方包下 `Feign` 的 `FallbackFactory`。
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.github.moyada/feign-help/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.github.moyada/feign-help)
![License MIT](https://img.shields.io/badge/MIT-342e38?style=flat-square&label=License)## 安装
添加 `feign-help` maven 依赖到项目 **模块**中 *pom.xml* :
```
io.github.moyada
feign-help
1.0.2-RELEASE```
## 使用
#### 引用 Feign 接口
```
public interface UserApi {@RequestMapping(value = "user/get", method = RequestMethod.GET)
Result getUser(@RequestParam("userId") Long userId);@RequestMapping(value = "user/create", method = RequestMethod.POST)
Result createUser(@RequestBody UserDTO data);@RequestMapping(value = "user/delete", method = RequestMethod.DELETE)
Result deleteUser(@RequestBody UserRequest data);
}
```#### 使用方构建 Feign Client
只需简单使用注解标记,经过编译过的class文件将会自动添加对应的 `Fallback`, `FallbackFactory`
```
@FallbackFactoryBuild
@FeignClient(name = "user", fallbackFactory = UserRemote.FallbackFactory.class)
public interface UserRemote extends UserApi {
}```
#### 经过编译后的 UserRemote.class 文件
```
@FeignClient(
name = "user",
fallbackFactory = UserRemote.FallbackFactory.class
)
public interface UserRemote extends UserApi {
@Component
public static class FallbackFactory implements feign.hystrix.FallbackFactory {
public FallbackFactory() {
}public UserRemote create(Throwable arg0) {
return new UserRemote.Fallback();
}
}public static class Fallback implements UserRemote {
public Fallback() {
}public Result getUser(@RequestParam("userId") Long userId) {
return null;
}public Result createUser(@RequestBody UserDTO data) {
return null;
}public Result deleteUser(@RequestBody UserRequest data) {
return null;
}
}
}
```## Contributors
| [![moyada](https://github.com/moyada.png?size=120)](https://github.com/r4phab) | [moyada](https://github.com/moyada) |
|:------------------------------------------------------------------------------:|--------------|