{"id":23099554,"url":"https://github.com/hiwepy/okhttp3-spring-boot-starter","last_synced_at":"2026-01-11T17:49:55.244Z","repository":{"id":57720025,"uuid":"134840496","full_name":"hiwepy/okhttp3-spring-boot-starter","owner":"hiwepy","description":"Spring Boot Starter For Okhttp 3.x","archived":false,"fork":false,"pushed_at":"2023-05-05T08:59:35.000Z","size":199,"stargazers_count":13,"open_issues_count":0,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2023-07-26T21:57:54.324Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hiwepy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-05-25T10:17:49.000Z","updated_at":"2023-02-03T10:38:59.000Z","dependencies_parsed_at":"2023-01-28T20:46:23.191Z","dependency_job_id":null,"html_url":"https://github.com/hiwepy/okhttp3-spring-boot-starter","commit_stats":null,"previous_names":["vindell/spring-boot-starter-okhttp3"],"tags_count":1,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hiwepy%2Fokhttp3-spring-boot-starter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hiwepy%2Fokhttp3-spring-boot-starter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hiwepy%2Fokhttp3-spring-boot-starter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hiwepy%2Fokhttp3-spring-boot-starter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hiwepy","download_url":"https://codeload.github.com/hiwepy/okhttp3-spring-boot-starter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230039010,"owners_count":18163345,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-16T23:19:35.450Z","updated_at":"2026-01-11T17:49:55.217Z","avatar_url":"https://github.com/hiwepy.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# okhttp3-spring-boot-starter\r\n\r\nSpring Boot Starter For Okhttp 3.x\r\n\r\n### 组件简介\r\n\r\n \u003e 基于 okhttp 3.x 的 Spring Boot Starter 实现\r\n \r\n 部分代码参考了：https://github.com/linux-china/spring-boot-starter-okhttp3\r\n\r\n### 使用说明\r\n\r\n##### 1、Spring Boot 项目添加 Maven 依赖\r\n\r\n``` xml\r\n\u003cdependency\u003e\r\n\t\u003cgroupId\u003ecom.github.hiwepy\u003c/groupId\u003e\r\n\t\u003cartifactId\u003eokhttp3-spring-boot-starter\u003c/artifactId\u003e\r\n\t\u003cversion\u003e${project.version}\u003c/version\u003e\r\n\u003c/dependency\u003e\r\n```\r\n\r\n##### 2、在`application.yml`文件中增加如下配置\r\n\r\n```yaml\r\n################################################################################################################\r\n###okhttp3基本配置：\r\n################################################################################################################\r\nokhttp3:\r\n  connect-timeout: 10s\r\n  read-timeout: 30s\r\n  write-timeout: 20s\r\n  log-level: BODY\r\n  pool:\r\n    # 最大空闲连接梳数量，超出该值后，连接用完后会被关闭，最多只会保留idleConnectionCount个连接数量\r\n    max-idle-connections: 256\r\n    # 最大瞬时处理连接数量\r\n    max-requests: 128\r\n    # 每个请求地址最大瞬时处理连接数量\r\n    max-requests-per-host: 24\r\n```\r\n\r\n##### 3、使用示例\r\n\r\n```java\r\n\r\nimport java.io.IOException;\r\n\r\nimport javax.annotation.PostConstruct;\r\n\r\nimport org.springframework.beans.factory.annotation.Autowired;\r\nimport org.springframework.boot.SpringApplication;\r\nimport org.springframework.boot.autoconfigure.SpringBootApplication;\r\n\r\n@SpringBootApplication\r\npublic class Application {\r\n\t\r\n\t@Autowired\r\n\tprivate OkHttpClient okHttpClient;\r\n\t\r\n\t@PostConstruct\r\n\tpublic void test() throws IOException {\r\n\t\t\r\n\t\t//调用ok的get请求\r\n       \tRequest request = new Request.Builder()\r\n                .get()\r\n                .url(url)\r\n                .build();\r\n       \t//同步请求方式\r\n\t   \tResponse theResponse = okHttpClient.newCall(newRequest).execute();\r\n\t   \t// 解析响应内容\r\n\t   \tResponseBody body = theResponse.body();\r\n\t   \t// 响应头信息\r\n\t   \tHeaders headers = theResponse.headers();\r\n\t   \t// 响应类型\r\n\t   \tMediaType mediaType = body.contentType();\r\n\t   \t// 成功状态\r\n\t\tif( theResponse.isSuccessful()) {\r\n\t\t\t// do something\r\n\t\t} \r\n\t\t\r\n\t}\r\n\t\r\n\t\r\n\tpublic static void main(String[] args) throws Exception {\r\n\t\tSpringApplication.run(Application.class, args);\r\n\t}\r\n\r\n}\r\n```\r\n\r\n## Jeebiz 技术社区\r\n\r\nJeebiz 技术社区 **微信公共号**、**小程序**，欢迎关注反馈意见和一起交流，关注公众号回复「Jeebiz」拉你入群。\r\n\r\n|公共号|小程序|\r\n|---|---|\r\n| ![](https://raw.githubusercontent.com/hiwepy/static/main/images/qrcode_for_gh_1d965ea2dfd1_344.jpg)| ![](https://raw.githubusercontent.com/hiwepy/static/main/images/gh_09d7d00da63e_344.jpg)|\r\n\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhiwepy%2Fokhttp3-spring-boot-starter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhiwepy%2Fokhttp3-spring-boot-starter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhiwepy%2Fokhttp3-spring-boot-starter/lists"}