spring-projects / spring-projects/spring-framework

Context created with beans' dependencies silently not set

Open
#36,656 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage
Dominant language
Java
Stars
60.2k
Forks
38.8k
Avg merge
5d 2h
Merged PRs (30d)
27

Description

We have quite a big application with a big spring context. We're migrating from Spring 5 to Spring 6 (6.2.16) and came across some strange behaviour.
In our application, we have a BeanDefinitionRegistryPostProcessor that programmatically registers bean definitions.
We are also using spring-security, and an issue seems to come from OAuth2AuthorizedClientManagerRegistrar calling getBeanNamesForType.
Now the issue: the application's spring context gets created with no errors or failures, however some singleton beans have their dependencies unset (null) even though they are annotated with @Autowired/@Resource.
As a result we seemingly have a running application that will throw NPEs at runtime - whenever a code path reaches the unset dependencies.

I've created a simple project that shows the issue.
Are we doing something wrong? I think that even if we are, the framework should not allow for the beans to be created with null dependencies.

spring-context-bug.zip

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the attached spring-context-bug.zip reproduction on Spring 6.2.16, then inspect the BeanDefinitionRegistryPostProcessor and the OAuth2AuthorizedClientManagerRegistrar call to getBeanNamesForType. Done means reproducing the context startup with all @Autowired and @Resource dependencies initialized, or documenting the specific configuration error that causes them to remain null.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.