{"id":18705689,"url":"https://github.com/kuangcp/springboot2-security-jwt","last_synced_at":"2025-08-03T13:15:14.347Z","repository":{"id":124451596,"uuid":"127104523","full_name":"Kuangcp/SpringBoot2-Security-Jwt","owner":"Kuangcp","description":"SpringBoot2 配置 JWT 案例","archived":false,"fork":false,"pushed_at":"2021-03-23T11:55:12.000Z","size":83,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-28T06:41:59.290Z","etag":null,"topics":["demo","jwt","springboot2","springboot2-security-jwt"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Kuangcp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-03-28T07:54:10.000Z","updated_at":"2021-03-23T11:55:14.000Z","dependencies_parsed_at":"2023-08-07T19:02:09.558Z","dependency_job_id":null,"html_url":"https://github.com/Kuangcp/SpringBoot2-Security-Jwt","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kuangcp%2FSpringBoot2-Security-Jwt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kuangcp%2FSpringBoot2-Security-Jwt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kuangcp%2FSpringBoot2-Security-Jwt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kuangcp%2FSpringBoot2-Security-Jwt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kuangcp","download_url":"https://codeload.github.com/Kuangcp/SpringBoot2-Security-Jwt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239568596,"owners_count":19660708,"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":["demo","jwt","springboot2","springboot2-security-jwt"],"created_at":"2024-11-07T12:11:39.574Z","updated_at":"2025-02-18T23:28:29.184Z","avatar_url":"https://github.com/Kuangcp.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SpringBoot2中使用Security整合JWT\n\n\u003e 参考 [原项目](https://github.com/freew01f/securing-spring-boot-with-jwts) 修改而来 | [原 博客](https://segmentfault.com/a/1190000009231329)\n\n运行起来后执行命令获取TOKEN\n\n`curl -H \"Content-Type: application/json\" -X POST -d '{\"username\":\"admin\",\"password\":\"123456\"}' http://127.0.0.1:8889/login`\n\n就会得到一个JSON 包含TOKEN\n\n```json\n{\n  \"result\": \"....\",\n  \"message\": \"\",\n  \"status\": 0\n}\n```\n使用上面获取的TOKEN值去获取用户信息\n\n`curl -H \"Content-Type: application/json\" -H \"Authorization: Bearer TOKEN值\" http://127.0.0.1:8889/list`\n \n 返回结果:\n```json\n{\n  \"result\":[\"tom\",\"jerry\"],\n  \"message\":\"\",\n  \"status\":0\n}\n```\n\n然后进行自定义的定制就行了, 整合数据库什么的\n\n\n### 特别注意跨域问题\n\u003e  [SpringBoot2的跨域配置](https://blog.csdn.net/kcp606/article/details/80036420)\n\u003e 由于JWT是基于JSON的， 所以前端的所有带TOKEN的请求都是会有两次请求的， 一次是预检请求方法是OPTIONS，一次是真正的请求， 所以要在Security的设置里放行所有 OPTIONS 的请求\n\n## 完整应用\n\u003e [毕业设计管理系统](https://github.com/Kuangcp/Graduate)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkuangcp%2Fspringboot2-security-jwt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkuangcp%2Fspringboot2-security-jwt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkuangcp%2Fspringboot2-security-jwt/lists"}