A spring-boot starter for retrofit, supports rapid integration and feature enhancements.(适用于retrofit的spring-boot-starter,支持快速集成和功能增强)
Java
1,916
409 commits
updated Sep 14, 2026
English | 简体中文 | 繁體中文 | 日本語 | 한국어 | Español | Türkçe | Русский
Retrofit 支持将 HTTP API 化成 Java 接口,本组件将 Retrofit 和 Spring Boot 深度整合,并支持了多种实用功能增强。
retrofit.global-converter-factories=com.github.lianjiatech.retrofit.spring.boot.core.jackson3.Jackson3ConverterFactory项目持续优化迭代,欢迎大家提 ISSUE 和 PR!能给一颗 star,是对我们持续更新的最大支持!
GitHub:https://github.com/LianjiaTech/retrofit-spring-boot-starter Gitee:https://gitee.com/lianjiatech/retrofit-spring-boot-starter
<dependency>
<groupId>com.github.lianjiatech</groupId>
<artifactId>retrofit-spring-boot-starter</artifactId>
<version>4.2.1</version>
</dependency>
引入依赖后即可使用。如遇问题,参见常见问题。
接口必须使用 @RetrofitClient 注解标记!
@RetrofitClient(baseUrl = "http://localhost:8080/api/user/")
public interface UserService {
/**
* 根据id查询用户姓名
*/
@POST("getName")
String getName(@Query("id") Long id);
}
注意:方法请求路径慎用
/开头。Retrofit 的路径拼接规则:如果baseUrl = http://localhost:8080/api/test/,方法路径person的完整路径为http://localhost:8080/api/test/person;而方法路径/person的完整路径为http://localhost:8080/person。
将接口注入到其他 Service 中即可使用:
@Service
public class BusinessService {
@Autowired
private UserService userService;
public void doBusiness() {
// 调用 userService
}
}
默认情况下,自动使用 SpringBoot 扫描路径进行 RetrofitClient 注册,也可以在配置类加上 @RetrofitScan 手动指定扫描路径。
HTTP 请求相关注解全部使用 Retrofit 原生注解:
| 注解分类 | 支持的注解 |
|---|---|
| 请求方式 | @GET @HEAD @POST @PUT @DELETE @OPTIONS @HTTP |
| 请求头 | @Header @HeaderMap @Headers |
| Query 参数 | @Query @QueryMap @QueryName |
| Path 参数 | @Path |
| Form 参数 | @Field @FieldMap @FormUrlEncoded |
| 请求体 | @Body |
| 文件上传 | @Multipart @Part @PartMap |
| URL 参数 | @Url |
详细信息参考 Retrofit 官方文档
如有任何问题,欢迎提 issue 或者加 QQ 群反馈。
群号:806714302

Latest release
Releases this year
A spring-boot starter for retrofit, supports rapid integration and feature enhancements.(适用于retrofit的spring-boot-starter,支持快速集成和功能增强)
Java
1,916
409 commits
updated Sep 14, 2026
English | 简体中文 | 繁體中文 | 日本語 | 한국어 | Español | Türkçe | Русский
Retrofit 支持将 HTTP API 化成 Java 接口,本组件将 Retrofit 和 Spring Boot 深度整合,并支持了多种实用功能增强。
retrofit.global-converter-factories=com.github.lianjiatech.retrofit.spring.boot.core.jackson3.Jackson3ConverterFactory项目持续优化迭代,欢迎大家提 ISSUE 和 PR!能给一颗 star,是对我们持续更新的最大支持!
GitHub:https://github.com/LianjiaTech/retrofit-spring-boot-starter Gitee:https://gitee.com/lianjiatech/retrofit-spring-boot-starter
<dependency>
<groupId>com.github.lianjiatech</groupId>
<artifactId>retrofit-spring-boot-starter</artifactId>
<version>4.2.1</version>
</dependency>
引入依赖后即可使用。如遇问题,参见常见问题。
接口必须使用 @RetrofitClient 注解标记!
@RetrofitClient(baseUrl = "http://localhost:8080/api/user/")
public interface UserService {
/**
* 根据id查询用户姓名
*/
@POST("getName")
String getName(@Query("id") Long id);
}
注意:方法请求路径慎用
/开头。Retrofit 的路径拼接规则:如果baseUrl = http://localhost:8080/api/test/,方法路径person的完整路径为http://localhost:8080/api/test/person;而方法路径/person的完整路径为http://localhost:8080/person。
将接口注入到其他 Service 中即可使用:
@Service
public class BusinessService {
@Autowired
private UserService userService;
public void doBusiness() {
// 调用 userService
}
}
默认情况下,自动使用 SpringBoot 扫描路径进行 RetrofitClient 注册,也可以在配置类加上 @RetrofitScan 手动指定扫描路径。
HTTP 请求相关注解全部使用 Retrofit 原生注解:
| 注解分类 | 支持的注解 |
|---|---|
| 请求方式 | @GET @HEAD @POST @PUT @DELETE @OPTIONS @HTTP |
| 请求头 | @Header @HeaderMap @Headers |
| Query 参数 | @Query @QueryMap @QueryName |
| Path 参数 | @Path |
| Form 参数 | @Field @FieldMap @FormUrlEncoded |
| 请求体 | @Body |
| 文件上传 | @Multipart @Part @PartMap |
| URL 参数 | @Url |
详细信息参考 Retrofit 官方文档
如有任何问题,欢迎提 issue 或者加 QQ 群反馈。
群号:806714302

Latest release
Releases this year