giuseppe-trisciuoglio avatar

Spring Boot Dependency Injection

Constructor injection is the right default for Spring, but a lot of legacy code still leans on field injection and nullable optionals. This skill walks you through separating mandatory from optional collaborators, using ObjectProvider for conditional features, and applying @Primary and @Qualifier only when you actually need them. The wiring validation section is solid: start with a minimal context test to catch bean problems before you write business logic. The no-op fallback pattern for optional dependencies is cleaner than sprinkling null checks everywhere. If you're refactoring services or onboarding someone who keeps reaching for @Autowired on fields, this gives you a concrete playbook.

skills.sh installs
3.9K
GitHub stars
369
last updated
Aug 21, 2026

Install

$ npx -y skills add giuseppe-trisciuoglio/developer-kit --skill spring-boot-dependency-injection --agent claude-code

Installs into .claude/skills of the current project.

Files

Spring Boot Dependency Injection

Overview

Provides constructor-first dependency injection patterns for Spring Boot:

  • mandatory collaborators via constructor injection
  • optional collaborators via ObjectProvider or no-op fallbacks
  • bean selection via @Primary and @Qualifier
  • validation via minimal context tests before full integration

When to Use

Use this skill when:

  • creating a new @Service, @Component, @Repository, or @Configuration class
  • replacing field injection in legacy Spring code
  • resolving multiple beans of the same type with qualifiers or primary beans
  • handling optional features, adapters, or integrations without null-driven wiring
  • reviewing circular dependencies or brittle context startup failures
  • preparing code for direct constructor-based unit testing

Instructions

1. Separate mandatory and optional collaborators

For each class, identify:

  • mandatory collaborators required for correct behavior
  • optional collaborators that enable integrations, caching, notifications, or feature-flagged behavior

Sponsors

Details

Repository
github.com/giuseppe-trisciuoglio/developer-kit
Categories
Debugging, Java & JVM, Design & UI/UX
First seen
May 16, 2026

More from giuseppe-trisciuoglio/developer-kit

All 102

Recommended

More Debugging
1giuseppe-trisciuoglio avatarunit-test-controller-layergiuseppe-trisciuoglio/developer-kitProvides patterns for unit testing REST controllers using MockMvc and @WebMvcTest. Generates controller tests that validates request/response mapping, validatio3.9Kskills.sh installs
2giuseppe-trisciuoglio avatarnextjs-data-fetchinggiuseppe-trisciuoglio/developer-kitProvides Next.js App Router data fetching patterns including SWR and React Query integration, parallel data fetching, Incremental Static Regeneration (ISR), rev3.9Kskills.sh installs
3github avatareval-driven-devgithub/awesome-copilotImprove AI application with evaluation-driven development. Define eval criteria, instrument the application, build golden datasets, observe and evaluate applica3.9Kskills.sh installs
4giuseppe-trisciuoglio avatarlangchain4j-vector-stores-configurationgiuseppe-trisciuoglio/developer-kitProvides configuration patterns for LangChain4J vector stores in RAG applications. Use when building semantic search, integrating vector databases (PostgreSQL/p3.8Kskills.sh installs
5giuseppe-trisciuoglio avataraws-sdk-java-v2-coregiuseppe-trisciuoglio/developer-kitProvides AWS SDK for Java 2.x client configuration, credential resolution, HTTP client tuning, timeout, retry, and testing patterns. Use when creating or harden3.8Kskills.sh installs
6dotnet avatarfetch-and-send-datadotnet/skillsCall APIs, load data into components, and handle the async lifecycle in Blazor. USE FOR fetching data from a backend, submitting data to an API, displaying load3.8Kskills.sh installs