Menu

1 / 2

We Removed Field Injection From 40 Services and Found 12 Circular Dependencies

DEV Community: java·Kamen·6 days ago
#U21eNA1N
#devtojava#devto#dev#spring#property
Long article (803 words) — no AI summary yet.
Reading 0:00
15s threshold

The task was supposed to be cosmetic. Forty Spring services still used @Autowired on private fields, the team had agreed constructor injection was the better default, and someone with a quiet sprint offered to convert them. It is the kind of change that tends to go in without much discussion, because it only moves dependencies from one place in a class to another. The application stopped starting after the third service. Spring refused with a message every Spring developer has seen at least once: the dependencies of some of the beans in the application context form a cycle. By the end of the conversion there were twelve of those cycles, and none of them was new.

They had been there all along, and what hid them was a single line of configuration. Since version 2.6, Spring Boot refuses circular references by default, whatever the injection style, so a cycle between two field-injected beans fails at startup too.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.