{"id":14973039,"url":"https://github.com/cofcool/chaos-server","last_synced_at":"2025-10-06T17:24:27.678Z","repository":{"id":52501563,"uuid":"168272285","full_name":"cofcool/chaos-server","owner":"cofcool","description":"基于 Spring Boot 的 Java Web Server 框架，简化开发","archived":false,"fork":false,"pushed_at":"2024-07-05T10:35:44.000Z","size":783,"stargazers_count":8,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-01T00:33:06.482Z","etag":null,"topics":["framework","java","mybatis","shiro","spring-boot","web"],"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/cofcool.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"security-shiro/pom.xml","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-01-30T03:23:23.000Z","updated_at":"2023-01-17T18:42:04.000Z","dependencies_parsed_at":"2024-09-23T12:40:45.818Z","dependency_job_id":null,"html_url":"https://github.com/cofcool/chaos-server","commit_stats":{"total_commits":231,"total_committers":3,"mean_commits":77.0,"dds":"0.19913419913419916","last_synced_commit":"d3572350a7d56a055c437f77a19524f9296ee11e"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cofcool%2Fchaos-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cofcool%2Fchaos-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cofcool%2Fchaos-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cofcool%2Fchaos-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cofcool","download_url":"https://codeload.github.com/cofcool/chaos-server/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238397262,"owners_count":19465145,"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":["framework","java","mybatis","shiro","spring-boot","web"],"created_at":"2024-09-24T13:47:59.755Z","updated_at":"2025-10-06T17:24:22.608Z","avatar_url":"https://github.com/cofcool.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 关于 Chaos Server\n\n**Chaos Server**, 基于 Spring Boot 的 Java Web Server 框架, 简化开发, 封装了常见的企业级项目开发框架, 如 `Mybaits`, `Spring Security`, `Shiro`, `JPA`等。\n\n\n最新版本为 ![maven central](https://img.shields.io/maven-central/v/net.cofcool.chaos/chaos-server.svg), Spring Boot 版本为 `3.1.1`, 通过`maven`引入\n\n```\n\u003cdependency\u003e\n  \u003cgroupId\u003enet.cofcool.chaos\u003c/groupId\u003e\n  \u003cartifactId\u003echaos-server-${MODULE_NAME}\u003c/artifactId\u003e\n  \u003cversion\u003e${VERSION}\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n查看[更新日志](./CHANGELOG.md)\n\n使用可查看 [示例项目](https://github.com/cofcool/chaos-server-demo.git)\n\n\n### 模块说明\n\n1. common 该模块定义了基本接口和类等\n2. core 核心实现, 包括拦截器, 国际化, JSON 解析等\n3. data-jpa `JPA` 相关的基础 `Service` 和工具类等\n5. extension 封装 `Redis`, `MongoDB` 等相关操作\n7. security-spring 封装了 `Spring Security`, 简化开发流程\n8. component-processor 编译时扫描 `BaseComponent` 注解, 该注解可标识基础组件, 避免组件调用混乱\n9. boot-starter 根据 `Spring Boot` 规范进行自动化配置\n\n### 配置 \n\n```properties\n# 是否调试模式\nchaos.development.debug=false\n# 项目版本\nchaos.development.version=100\n# 是否开启验证码\nchaos.auth.using-captcha=false\n# 定义扫描 Scanned 注解的路径\nchaos.development.annotation-path=net.cofcool.chaos.server.demo\n# 授权路径配置, 用\";\"分割, \"Spring Security\" 项目, 该配置为匿名访问路径; \"Shiro\" 为授权路径配置, 即\"filterChainDefinitions\"\nchaos.auth.urls=/auth/**\\=anon;/error\\=anon;/**\\=authc\n# 登陆路径\nchaos.auth.login-url=/auth/login\n# 注入数据key配置, 多个时以\",\"分隔\nchaos.auth.checked-keys=id\n```\n\n### 使用\n\n业务相关Service可继承`DataAccess`接口, 实现类可继承`SimpleService`抽象类。\n\n\n使用`Page`类封装分页的相关数据, ORM模块的`Paging`继承并扩展。\n\n* Mybatis: 通过 `Mybatis Plus` 分页插件分页。\n* Jpa: 通过`Pageable`分页。\n\n**异常**处理时, 自定义业务相关异常需继承`ServiceException`。如需设定异常级别, 实现`ExceptionLevel`接口即可, 该级别影响异常的打印。`ServiceException`已实现该接口, 默认为最高级别。\n\n#### 授权处理\n\n封装了`Apache Shiro`和`Spring Security`, 应用可依赖`security-shiro`模块或`security-spring`模块来实现授权管理。\n\n\u003cimg src=\"./docs/auth_login.svg\" alt=\"login\"/\u003e\n\n`AuthService`类定义了登录等操作, 应用不需要实现该类, 只需引用该组件即可, 登录由\"filter\"完成，因此不需要主动调用该方法。\n\n`UserAuthorizationService`定义应用操作, 应用需实现该类。\n\n`PasswordProcessor`定义密码处理操作, 应用需实现该类。\n\n`User`存储用户信息。\n\n`spring-security` 配置时注意 `chaos.auth.cors-enabled` 和 `chaos.auth.csrf-enabled` 配置项。\n\n#### Service 层\n\n`DataAccess`定义\"Service\"常用的方法。\n\n`Result`封装运行结果，提供两个子接口，`QueryResult`封装查询结果，其它情况由`ExecuteResult`处理。\n\n抽象类`SimpleService`实现`DataAccess`类，实现`query`方法，简化分页操作，定义`queryWithPage`方法，用于分页查询。通过`ExceptionCodeManager`描述执行状态错误码等。JPA 应用的\"Service\"可继承`SimpleJpaService`。\n\n#### Controller 层\n\n默认提供三种\"Controller(使用`Scanned`注解)\"代理类:\n\n* 注入用户数据到请求参数中, 即数据隔离，实现类为`ApiProcessingInterceptor`\n* 请求日志打印，实现类为`LoggingInterceptor`\n* 参数校验，实现类为`ValidateInterceptor`\n\n##### 1. Json解析\n\n`ResponseBodyMessageConverter`支持把`Result`, `Number`, `String`, `Result.ResultState`等对象转为`Message`对象，即可保证接口返回的数据统一为`Message`规定的格式(), 应用可调用`Message.of()`方法创建实例。\n\n\n#### 异常处理\n\n##### 默认处理异常类型\n\n`GlobalHandlerExceptionResolver`处理在请求中发生的异常，包括如下异常:\n\n* ServiceException\n* NullPointerException, IndexOutOfBoundsException,  NoSuchElementException\n* HttpMessageNotReadableException\n* UnsupportedOperationException\n* MethodArgumentNotValidException\n* DataAccessException\n\n除以上异常外，其它异常由 Spring 的`DefaultHandlerExceptionResolver`处理。\n\n把异常信息包装为`Message`对象，保证发生异常时的响应格式符合接口规范。\n\n注意：当运行在`Debug`模式时，会优先调用`DefaultHandlerExceptionResolver`处理异常。\n\n##### 描述信息\n\n应用中的描述信息统一由 `ExceptionCodeManager` 处理。`ExceptionCodeDescriptor` 封装了描述信息，默认提供了两种类型:\n\n* SimpleExceptionCodeDescriptor\n* ResourceExceptionCodeDescriptor\n\n`SimpleExceptionCodeDescriptor`为默认配置，包含了常见的描述代码和描述信息，例如操作成功，操作失败等。\n\n`ResourceExceptionCodeDescriptor` 从\"messages\"文件中读取配置的描述信息。\n ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcofcool%2Fchaos-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcofcool%2Fchaos-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcofcool%2Fchaos-server/lists"}