After upgrading spring-boot from 2.5.11 to 2.6.7, it seems you can no longer inject dependant beans from within a @PostConstruct In 2.5.11, getBeansOfType would find the Majigger, even though Majigger depends on TestMajigger. In 2.6.7, it does not find Majigger, so I throw an exception.

If I change it so that Majigger does not depend on TestMajigger, then TestMajigger can find a Majigger.

@Service
@RequiredArgsConstructor
public class TestMajigger {
  private final ApplicationContext applicationContext;

  @PostConstruct
  public void init() {
    var majiggers = applicationContext.getBeansOfType(Majigger.class);
    if (majiggers.isEmpty()) {
      throw new IllegalStateException("No majiggers!");
    }
  }
}
@Service
@RequiredArgsConstructor
public class Majigger {
  private final TestMajigger testMajigger;
}

Is this behavioral change intended?

Comment From: wilkinsona

I suspect that this is because circular references are now prohibited but default. Please try enabling circular references to see if it resolves the problem. If it does not and you would like us to spend some more time investigating, please spend some time providing a complete yet minimal sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.

Comment From: lbenedetto

Enabling circular dependencies fixes the issue.

Though I wish that spring had given errors about circular dependencies in this case rather than silently failing to resolve the beans.

Comment From: wilkinsona

Enabling circular dependencies fixes the issue

Thanks for letting us know.

Though I wish that spring had given errors about circular dependencies in this case

You may want to raise that with the Spring Framework team.