闲社服务运行正常AI智能体自动化平台
j

Spring Boot开发

技能标识:java-spring-boot

Build production Spring Boot applications - REST APIs, Security, Data, Actuator

作者:admin | 来源记录:ClawHub
登记来源
ClawHub
版本
V 1.0.0
检测标记
后台标记通过
免费
免费获取
0
收藏
来源与检测标记为平台登记信息,并不代表已展示可复核的检测报告。使用前请核对版本、依赖和所需权限,建议先在隔离环境中运行。
概述
安装方式
版本历史

Spring Boot开发

Java Spring Boot 技能

遵循现代最佳实践构建生产级Spring Boot应用程序。

概述

本技能涵盖Spring Boot开发,包括REST API、安全配置、数据访问、Actuator监控和云集成。遵循Spring Boot 3.x模式,强调生产就绪性。

何时使用本技能

在需要以下场景时使用:

  • - 使用Spring MVC/WebFlux创建REST API
  • 配置Spring Security(OAuth2、JWT)
  • 使用Spring Data设置数据库访问
  • 使用Actuator启用监控
  • 与Spring Cloud集成

涵盖主题

Spring Boot核心

  • - 自动配置和启动器
  • 应用属性和配置文件
  • Bean生命周期和配置
  • DevTools和热重载

REST API开发

  • - @RestController和@RequestMapping
  • 请求/响应处理
  • 使用Bean Validation进行验证
  • 使用@ControllerAdvice进行异常处理

Spring Security

  • - SecurityFilterChain配置
  • OAuth2和JWT认证
  • 方法安全(@PreAuthorize)
  • CORS和CSRF配置

Spring Data JPA

  • - Repository模式
  • 查询方法和@Query
  • 分页和排序
  • 审计和事务

Actuator与监控

  • - 健康检查和探针
  • 使用Micrometer的指标
  • 自定义端点
  • Prometheus集成

快速参考

java
// REST控制器
@RestController
@RequestMapping(/api/users)
@Validated
public class UserController {

@GetMapping(/{id})
public ResponseEntity getUser(@PathVariable Long id) {
return userService.findById(id)
.map(ResponseEntity::ok)
.orElse(ResponseEntity.notFound().build());
}

@PostMapping
public ResponseEntity createUser(@Valid @RequestBody UserRequest request) {
User user = userService.create(request);
URI location = URI.create(/api/users/ + user.getId());
return ResponseEntity.created(location).body(user);
}
}

// 安全配置
@Configuration
@EnableWebSecurity
public class SecurityConfig {

@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
return http
.csrf(csrf -> csrf.disable())
.sessionManagement(s -> s.sessionCreationPolicy(STATELESS))
.authorizeHttpRequests(auth -> auth
.requestMatchers(/actuator/health/).permitAll()
.requestMatchers(/api/public/).permitAll()
.anyRequest().authenticated())
.oauth2ResourceServer(oauth2 -> oauth2.jwt(Customizer.withDefaults()))
.build();
}
}

// 异常处理器
@RestControllerAdvice
public class GlobalExceptionHandler {

@ExceptionHandler(EntityNotFoundException.class)
public ProblemDetail handleNotFound(EntityNotFoundException ex) {
return ProblemDetail.forStatusAndDetail(NOT_FOUND, ex.getMessage());
}
}

配置模板

yaml

application.yml


spring:
application:
name: ${APP_NAME:my-service}
profiles:
active: ${SPRINGPROFILESACTIVE:local}
jpa:
open-in-view: false
properties:
hibernate:
jdbc.batch_size: 50

management:
endpoints:
web:
exposure:
include: health,info,metrics,prometheus
endpoint:
health:
probes:
enabled: true

server:
error:
include-stacktrace: never

常见模式

分层架构

Controller → Service → Repository → Database
↓ ↓ ↓
DTOs Entities Entities

验证模式

java public record CreateUserRequest( @NotBlank @Size(max = 100) String name, @Email @NotBlank String email, @NotNull @Min(18) Integer age ) {}

故障排除

常见问题

问题原因解决方案
Bean未找到缺少@Component添加注解或@Bean
循环依赖
构造函数注入 | 使用@Lazy或重构 | | 401未授权 | 安全配置 | 检查permitAll路径 | | 启动缓慢 | 大量自动配置 | 排除未使用的启动器 |

调试属性

properties debug=true logging.level.org.springframework.security=DEBUG spring.jpa.show-sql=true

调试清单

□ 检查 /actuator/conditions
□ 验证激活的配置文件
□ 审查安全过滤器链
□ 检查Bean定义
□ 测试健康端点

使用方式

Skill(java-spring-boot)

相关技能

  • - java-testing - Spring测试模式
  • java-jpa-hibernate - 数据访问

标签

skill ai

通过对话安装

以下为平台配置的接入选项,并非逐项实测通过。能否安装取决于客户端支持、技能来源和运行环境:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 java-spring-boot-1776076622 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 java-spring-boot-1776076622 技能

通过命令行安装

skillhub install java-spring-boot-1776076622

下载

⬇ 下载 java-spring-boot v1.0.0(免费)

文件大小: 7.08 KB | 发布时间: 2026-4-14 11:21

v1.0.0 最新 2026-4-14 11:21
Initial release of java-spring-boot skill.

- Build production-ready Spring Boot applications: REST APIs, Security, Data, Actuator.
- Supports Spring Boot 3.x features and best practices.
- Includes guides and code snippets for REST, Security, Data JPA, and Actuator integration.
- Parameter validation for spring_version and module focus.
- Troubleshooting section with common Spring Boot issues and debug tips.
返回顶部