java-spring-boot について
Java 開発者向けの Spring Boot スキルです。Spring Boot 3.x のパターンに沿って、REST API、セキュリティ、データアクセス、監視を扱います。
主な機能
- 01Spring Boot の基本設定
- 02REST API 開発と入力検証
- 03OAuth2 と JWT のセキュリティ設定
- 04Spring Data JPA によるデータアクセス
- 05Actuator の監視とメトリクス
活用シーン
- 01Spring MVC または WebFlux API の構築
- 02認証とメソッドセキュリティの設定
- 03データベース接続とページングの追加
- 04ヘルスチェックと Prometheus メトリクスの追加
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ pluginagentmarketplace/ custom-plugin-java --skill java-spring-bootインストール後、Claude Code で/java-spring-bootを入力して読み込まれたか確認します。
同梱ファイル
SKILL.md と一緒にインストールされる参考資料やスクリプト。
assets/config.yamlschema.jsonreferences/GUIDE.mdPATTERNS.mdscripts/validate.py詳細
Java Spring Boot スキル
最新のベストプラクティスに従って、本番環境に対応した Spring Boot アプリケーションを構築します。
概要
このスキルでは、REST API、セキュリティ設定、データアクセス、Actuator によるモニタリング、クラウド連携など、Spring Boot の開発を扱います。本番環境への対応を重視し、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
- リポジトリパターン
- クエリメソッドと @Query
- ページネーションとソート
- 監査とトランザクション
Actuator とモニタリング
- ヘルスチェックとプローブ
- Micrometer によるメトリクス
- カスタムエンドポイント
- Prometheus との連携
クイックリファレンス
// REST Controller
@RestController
@RequestMapping("/api/users")
@Validated
public class UserController {
@GetMapping("/{id}")
public ResponseEntity<User> getUser(@PathVariable Long id) {
return userService.findById(id)
.map(ResponseEntity::ok)
.orElse(ResponseEntity.notFound().build());
}
@PostMapping
public ResponseEntity<User> createUser(@Valid @RequestBody UserRequest request) {
User user = userService.create(request);
URI location = URI.create("/api/users/" + user.getId());
return ResponseEntity.created(location).body(user);
}
}
// Security Configuration
@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();
}
}
// Exception Handler
@RestControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler(EntityNotFoundException.class)
public ProblemDetail handleNotFound(EntityNotFoundException ex) {
return ProblemDetail.forStatusAndDetail(NOT_FOUND, ex.getMessage());
}
}
設定テンプレート
# application.yml
spring:
application:
name: ${APP_NAME:my-service}
profiles:
active: ${SPRING_PROFILES_ACTIVE: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
バリデーションパターン
public record CreateUserRequest(
@NotBlank @Size(max = 100) String name,
@Email @NotBlank String email,
@NotNull @Min(18) Integer age
) {}
トラブルシューティング
よくある問題
| 問題 | 原因 | 解決策 |
|---|---|---|
| Bean が見つからない | @Component が不足している | アノテーションまたは @Bean を追加する |
| 循環依存 | コンストラクターインジェクション | @Lazy を使用するか、リファクタリングする |
| 401 Unauthorized | セキュリティ設定 | permitAll のパスを確認する |
| 起動が遅い | 重い自動設定 | 使用していないスターターを除外する |
デバッグ用プロパティ
debug=true
logging.level.org.springframework.security=DEBUG
spring.jpa.show-sql=true
デバッグチェックリスト
□ Check /actuator/conditions
□ Verify active profiles
□ Review security filter chain
□ Check bean definitions
□ Test health endpoints
使用方法
Skill("java-spring-boot")
関連スキル
java-testing- Spring のテストパターンjava-jpa-hibernate- データアクセス
コメント
Markdown 対応