agentleFS
yalishevantyalishevant/kotlin-backend-agent-skills/.agents/skills/spring-context-di-reasoning/SKILL.md

spring-context-di-reasoning

Skill18 starsChanged 9 months agoMITView on GitHub

Diagnose Spring application context startup failures, bean graph problems, missing or duplicate beans, circular dependencies, conditional auto-configuration mismatches, and profile-related wiring issues in Kotlin + Spring projects. Use when the app does not start, a bean is not created or is created unexpectedly, auto-configuration behaves strangely, or a minimal DI fix is needed instead of a broad rewrite.

1 other project uses a version of this, 1 of them edited.

Adopted by

Most recently taken up by

The file

Show its rules and text

We split this skill into the rules it gives an agent

31 rules. About 0 are common, 17 are distinctive, and 14 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈17

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 14

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Read the full exception chain, not only the top exception.

    line 17
  2. Very specific:

    Read the startup log lines around the first failure and around any Caused by: entries.

    line 18
  3. Very specific:

    Read the relevant @Configuration, component classes, @Bean methods, @ConfigurationProperties, and active profiles.

    line 19
  4. Very specific:

    Read the build context if it is not already known.

    line 20
  5. Distinctive:

    If a condition evaluation report or auto-configuration report exists, use it.

    line 21
  6. Distinctive:

    Check these categories in order:

    line 35
  7. Distinctive:

    Prefer fixes in this order:

    line 67
  8. Very specific:

    Use @Lazy only as a deliberate escape hatch, and explain the tradeoff.

    line 74
  9. Very specific:

    Check whether a @Configuration class uses proxyBeanMethods = false.

    line 78
  10. Very specific:

    Check whether the missing bean is actually a FactoryBean product versus the factory itself.

    line 79
  11. Very specific:

    Check generic type narrowing.

    line 80
  12. Very specific:

    Check collection and map injection semantics.

    line 81
  13. Very specific:

    Check whether ObjectProvider<T>, Optional<T>, or lazy lookup is masking a missing dependency until first use.

    line 82
  14. Very specific:

    Check whether @ConditionalOnMissingBean, @ConditionalOnSingleCandidate, or ordering annotations caused an auto-configuration branch to back …

    line 83
  15. Distinctive:

    Check for environment post-processors, imported configs, or test slices that change the bean graph compared with main runtime.

    line 84
  16. Distinctive:

    If the project uses AOT or native image workflows, check whether reflection or generated context metadata, not the source annotations …

    line 85
  17. Distinctive:

    Prefer following the bean creation path from the first failing constructor argument over scanning all annotations in the module.

    line 89
  18. Distinctive:

    If one fix would "make startup pass" but leaves the graph semantically wrong, reject it and explain the deeper issue.

    line 90
  19. Distinctive:

    When the problem surfaces only in tests, compare the test slice graph with the production graph before changing production code.

    line 91
  20. Distinctive:

    If a bean exists but the wrong implementation is selected, explain the selection mechanism, not only the missing qualifier.

    line 92
  21. Distinctive:

    If property binding and bean creation both fail, fix property binding first.

    line 93
  22. Very specific:

    Do not suggest @ComponentScan("*"), giant scanBasePackages, or other "scan the world" fixes.

    line 107
  23. Distinctive:

    Do not guess bean names or qualifiers that are not present in the code.

    line 108
  24. Distinctive:

    Do not recommend disabling auto-configuration broadly to silence a symptom.

    line 109
  25. Very specific:

    Do not use @Lazy as the default answer to cycles.

    line 110
  26. Distinctive:

    Do not ignore profiles, conditions, or property sources when explaining bean behavior.

    line 111
  27. Very specific:

    Verify @EnableConfigurationProperties or equivalent registration if properties beans are missing.

    line 115
  28. Distinctive:

    Verify whether the failing type is an interface with multiple implementations.

    line 116
  29. Distinctive:

    Verify whether a bean lives in another Gradle module that is not on the runtime classpath.

    line 117
  30. Very specific:

    Verify whether a @TestConfiguration or test slice changes the graph only in tests.

    line 118
  31. Distinctive:

    Verify whether the issue is really a classpath problem disguised as a bean problem.

    line 119

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Spring Context DI Reasoning

Source mapping: Tier 1 critical skill derived from Kotlin_Spring_Developer_Pipeline.md (SK-02).

Mission

Reconstruct why the Spring container made a specific decision and propose the narrowest fix that restores correct wiring. Assume the visible exception is often a wrapper, not the real cause.

Collect Evidence First

  • Read the full exception chain, not only the top exception.
  • Read the startup log lines around the first failure and around any Caused by: entries.
  • Read the relevant @Configuration, component classes, @Bean methods, @ConfigurationProperties, and active profiles.
  • Read the build context if it is not already known. Reuse output from project-context-ingestion when available.
  • If a condition evaluation report or auto-configuration report exists, use it.

Reconstruct The Bean Path

  • Identify the bean that failed first.
  • Walk constructor arguments, method parameters, and factory methods to build the dependency chain.
  • Separate symptom from cause:
    • BeanCreationException is usually a wrapper.
    • UnsatisfiedDependencyException usually points to a missing or ambiguous dependency one hop deeper.
    • property binding failures often surface as bean creation failures.
  • Record whether the failing bean is user-defined, auto-configured, conditional, profile-specific, or imported from another module.

Diagnose By Category

Check these categories in order:

  1. Missing bean:
    • package not scanned
    • bean class not annotated
    • @Bean method not imported
    • wrong module dependency
  2. Ambiguous bean:
    • multiple beans of same type
    • missing @Qualifier
    • missing @Primary
  3. Conditional mismatch:
    • @Profile not active
    • @ConditionalOnProperty false or missing
    • classpath condition not satisfied
  4. Configuration binding failure:
    • wrong prefix
    • missing required property
    • invalid type conversion
  5. Circular dependency:
    • constructor cycle
    • configuration class cycle
    • bean factory method recursion
  6. Auto-configuration collision:
    • user bean unintentionally overrides or blocks auto-config
    • excluded auto-config removes a dependency chain
  7. Lifecycle or initialization side effects:
    • bean does work too early in @PostConstruct
    • external system call during initialization

Fix Hierarchy

Prefer fixes in this order:

  1. Correct the missing import, annotation, qualifier, or profile.
  2. Correct the configuration property source or binding model.
  3. Narrow the scan or import boundary to the intended package or module.
  4. Resolve ambiguity with @Qualifier or @Primary.
  5. Refactor an actual cycle into a cleaner dependency direction.
  6. Use @Lazy only as a deliberate escape hatch, and explain the tradeoff.

Advanced Container Traps

  • Check whether a @Configuration class uses proxyBeanMethods = false. In that mode, direct calls between @Bean methods do not return the managed singleton unless dependencies are expressed through method parameters.
  • Check whether the missing bean is actually a FactoryBean product versus the factory itself.
  • Check generic type narrowing. Foo<Bar> and Foo<Baz> may both exist while raw-type reasoning makes the graph look ambiguous or missing.
  • Check collection and map injection semantics. List<BeanType> ordering, bean names, and conditional registration can hide the real cause.
  • Check whether ObjectProvider<T>, Optional<T>, or lazy lookup is masking a missing dependency until first use.
  • Check whether @ConditionalOnMissingBean, @ConditionalOnSingleCandidate, or ordering annotations caused an auto-configuration branch to back off unexpectedly.
  • Check for environment post-processors, imported configs, or test slices that change the bean graph compared with main runtime.
  • If the project uses AOT or native image workflows, check whether reflection or generated context metadata, not the source annotations alone, is the true source of failure.

Expert Heuristics

  • Prefer following the bean creation path from the first failing constructor argument over scanning all annotations in the module.
  • If one fix would "make startup pass" but leaves the graph semantically wrong, reject it and explain the deeper issue.
  • When the problem surfaces only in tests, compare the test slice graph with the production graph before changing production code.
  • If a bean exists but the wrong implementation is selected, explain the selection mechanism, not only the missing qualifier.
  • If property binding and bean creation both fail, fix property binding first. Bean graph symptoms often disappear afterward.

Output Contract

Return these sections:

  • Diagnosis: the most probable root cause in one or two sentences.
  • Evidence: the exact lines, bean path, condition, or configuration fact that supports the diagnosis.
  • Minimal fix: the smallest code or config change that addresses the root cause.
  • Alternatives: only if there is more than one legitimate fix.
  • Verification: how to confirm the fix, such as ./gradlew test, bootRun, or a specific startup assertion.

Guardrails

  • Do not suggest @ComponentScan("*"), giant scanBasePackages, or other "scan the world" fixes.
  • Do not guess bean names or qualifiers that are not present in the code.
  • Do not recommend disabling auto-configuration broadly to silence a symptom.
  • Do not use @Lazy as the default answer to cycles.
  • Do not ignore profiles, conditions, or property sources when explaining bean behavior.

Common Spring-Specific Checks

  • Verify @EnableConfigurationProperties or equivalent registration if properties beans are missing.
  • Verify whether the failing type is an interface with multiple implementations.
  • Verify whether a bean lives in another Gradle module that is not on the runtime classpath.
  • Verify whether a @TestConfiguration or test slice changes the graph only in tests.
  • Verify whether the issue is really a classpath problem disguised as a bean problem.

Quality Bar

A good run of this skill explains why Spring made the wrong decision and gives a minimal, testable fix. A bad run waves at annotations, suggests broad scans, or ignores the dependency chain that actually failed.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.