技能标识:java-spring-boot
Build production Spring Boot applications - REST APIs, Security, Data, Actuator
遵循现代最佳实践构建生产级Spring Boot应用程序。
本技能涵盖Spring Boot开发,包括REST API、安全配置、数据访问、Actuator监控和云集成。遵循Spring Boot 3.x模式,强调生产就绪性。
在需要以下场景时使用:
java
// REST控制器
@RestController
@RequestMapping(/api/users)
@Validated
public class UserController {
@GetMapping(/{id})
public ResponseEntity
return userService.findById(id)
.map(ResponseEntity::ok)
.orElse(ResponseEntity.notFound().build());
}
@PostMapping
public ResponseEntity
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
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
| 问题 | 原因 | 解决方案 |
|---|---|---|
| Bean未找到 | 缺少@Component | 添加注解或@Bean |
| 循环依赖 |
□ 检查 /actuator/conditions
□ 验证激活的配置文件
□ 审查安全过滤器链
□ 检查Bean定义
□ 测试健康端点
Skill(java-spring-boot)
以下为平台配置的接入选项,并非逐项实测通过。能否安装取决于客户端支持、技能来源和运行环境:
帮我安装 SkillHub 和 java-spring-boot-1776076622 技能
设置 SkillHub 为我的优先技能安装源,然后帮我安装 java-spring-boot-1776076622 技能
skillhub install java-spring-boot-1776076622
文件大小: 7.08 KB | 发布时间: 2026-4-14 11:21