OpeningO-spring-boot-xSpring Boot 扩展

联合创作 · 2023-09-20 02:28

spring-boot-x是springboot应用的扩展。

特性清单

  • 手动事务管理 [2021.6.29更新]

  • 分布式id生成器gedid,DidLoader [ 2021.6.25更新 ]

  • Safety工具 [ 2021.6.25更新 ]

  • 请求日志,包括请求源、请求目标、请求参数、处理时间、错误异常等信息;

  • 请求响应参数的自动装配(映射);

  • 跨域的配置;

  • 嵌入SpringBoot的异常处理机制,可以将原来的错误信息中插入其他信息、或将其解析或转换为其他信息;

  • SpringBootstarter动态装配或在yml中配置相关特性;

  • 简化的Redis操作;

  • 提炼ElasticsearchHighlevelClient常用操作;

  • feign的请求头参数的处理:合并上下游的请求头参数,并发场景的数据处理策略;

  • 基于DruidHikari的动态路由RoutingDataSource

  • SpringBoot应用的配置信息的自动拷贝;

1. 请求日志

****************************************************************
:: SpringApplicationX :: for current request report information 
****************************************************************
Client IP  : 127.0.0.1 
Request Time  : 2020-07-12T19:24:40.249 
Controller  : org.openingo.x.controller.UserController.(UserController.java:1)
URI  : http://localhost:8080/json 
Handler(Action)  : json
Method  : GET
Processing Time  : 0.002s
Header(s)  : [user-agent:"PostmanRuntime/7.25.0", cache-control:"no-cache", postman-token:"b29a0616-7e31-4150-b022-4bf3680bf771", host:"localhost:8080", accept-encoding:"gzip, deflate, br", connection:"keep-alive", content-length:"21", Content-Type:"application/json;charset=UTF-8"]
Body  : {"name":"qicz"}
Response  : {"name":"qicz","age":18}
----------------------------------------------------------------

2. 错误处理

可以继承AbstractServiceErrorAttributes,扩展exception的处理

{
    "timestamp": "2020-07-13T05:49:06.071+0000",
    "status": 500,
    "error": "Internal Server Error",
    "exception": "org.openingo.spring.exception.ServiceException",
    "message": "testing exception",
    "path": "/ex",
    "handler": "public java.util.Map org.openingo.x.controller.UserController.ex()",
    "openingo.error": {
        "ex": "org.openingo.spring.exception.ServiceException: testing exception",
        "em": "testing exception",
        "error": "Internal Server Error",
        "ec": "ERROR_CODE"
    }
}

3. 使用及配置

加入spring-boot-x依赖(已托管在中央仓库),在启动class上加入@EnableExtension注解即可使用spring-boot-x的扩展功能。

通过application.yml/application.properties可以对请求日志redis等操作进行开关。默认情况下,请求日志及错误扩展为开启状态。

openingo:
  redis:
    enable: true
  http:
    request:
      cors:
        allowed-header: "*"
        enable: true
        allowed-all: true
      log:
        enable: true
      error:
        enable: true

 

浏览 2
点赞
评论
收藏
分享

手机扫一扫分享

编辑
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

编辑
举报