spring-projects / spring-projects/spring-framework
Context created with beans' dependencies silently not set
Nobody has claimed this yet.
- 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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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