添加健康检查接口
- 新增 /health 健康检查端点,返回服务状态信息 - 新增 /health/ping 简单检查端点,返回 pong 响应 - 配置 Spring Security 允许健康检查端点无需认证访问 - 支持负载均衡器和监控系统进行服务可用性检查
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
package com.starry.admin.modules.system.controller;
|
||||
|
||||
import com.starry.common.result.R;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Health Check Controller
|
||||
* @author admin
|
||||
* @since 2025/08/30
|
||||
*/
|
||||
@Api(tags = "健康检查", description = "服务健康状态检查接口")
|
||||
@RestController
|
||||
@RequestMapping("/health")
|
||||
public class HealthController {
|
||||
|
||||
@ApiOperation(value = "健康检查", notes = "检查服务是否正常运行")
|
||||
@ApiResponses({
|
||||
@ApiResponse(code = 200, message = "服务正常运行")
|
||||
})
|
||||
@GetMapping
|
||||
public R health() {
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("status", "UP");
|
||||
data.put("message", "Hello, I'm alive!");
|
||||
data.put("timestamp", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||
data.put("service", "peipei-backend");
|
||||
return R.ok(data);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "简单检查", notes = "最简单的存活检查")
|
||||
@ApiResponses({
|
||||
@ApiResponse(code = 200, message = "服务正常")
|
||||
})
|
||||
@GetMapping("/ping")
|
||||
public R ping() {
|
||||
return R.ok("pong");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user