Why this matters
Using field injection (`@Autowired` on fields) in Spring components increases coupling and testability issues. Constructor injection is more reliable and preferred.
Ensure that constructor injection is used instead of field injection (`@Autowired` on fields) in Spring components for better testability.
Using field injection (`@Autowired` on fields) in Spring components increases coupling and testability issues. Constructor injection is more reliable and preferred.
Side-by-side examples engineers can pattern-match during review.
@Controller
public class HelloWorld {
@Autowired
private String title = null; // Noncompliant
}// (no example provided)@Controller
public class HelloWorld {
@Autowired
private String title = null; // Noncompliant
}From the same buckets as this rule.
For changes that affect architecture, data models, external APIs, security posture, deployment topology, or cost (>10%), create an ADR in docs/adr/ using the standard template (Context, Decision, Consequences) and link the PR and issue IDs.