Question 1
An application that started successfully on Spring Boot 2.5 fails to start after upgrading to Spring Boot 2.7: two singleton beans depend on each other through setter (field) injection, and startup now reports an unsatisfied circular reference. Which TWO of the following are valid ways to make the application start again? Select TWO.
A. Set `spring.main.allow-circular-references=true`, restoring the pre-2.6 behavior in which the container resolves the setter/field circular reference (Spring logs a warning recommending you refactor).Correct answer
Correct. Spring Boot 2.6 prohibits circular references by default; this property re-enables the earlier resolution behavior for the whole application. It is the documented compatibility switch, and Spring still warns that the cycle should be refactored away.
B. Annotate one of the two injection points with `@Lazy` so a lazy-resolving proxy is injected, meaning the two beans no longer need each other fully initialized at the same moment and the cycle is broken.Correct answer
Correct. `@Lazy` on one side injects a proxy that resolves the target on first use, so neither bean requires the other to be fully constructed during its own creation. This breaks the cycle locally without allowing circular references globally.
C. Mark the two beans `@Primary` so the container can choose between them and the circular reference is resolved.
`@Primary` disambiguates among multiple candidate beans of the same type at an injection point; it has nothing to do with a circular dependency between two distinct beans and would not affect startup here.
D. Switch both beans to constructor injection, since the 2.6 change only affects setter injection and constructor injection is unaffected.
Reversed. Constructor-injection circular dependencies always fail with `BeanCurrentlyInCreationException`, and did so before 2.6. The 2.6 change is precisely that setter/field cycles, previously resolved, are now prohibited by default — moving to constructor injection makes this cycle fail harder, not start.
E. Downgrade is the only option, because `spring.main.allow-circular-references` does not exist in Spring Boot 2.7.
The property exists in Boot 2.6+ and is the intended switch for exactly this situation, so no downgrade is required.
Explanation
Spring Boot 2.6 changed the default so that circular references between beans are prohibited; an application that previously relied on Spring resolving a setter/field-injection cycle now fails at startup after upgrading. Two valid remedies exist: re-enable the legacy behavior globally with `spring.main.allow-circular-references=true` (Spring warns and recommends refactoring), or break the cycle locally by marking one injection point `@Lazy`, so a proxy is injected and the beans no longer require each other to be fully initialized simultaneously. Marking beans `@Primary` addresses candidate ambiguity rather than cycles; converting to constructor injection makes a cycle fail harder, because constructor cycles always throw `BeanCurrentlyInCreationException`; and the property does exist in 2.7, so no downgrade is needed.