-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Add support for JSR-330 and Jakarta @Inject
for autowiring test constructors
#29851
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@Inject
annotation in spring-test
@Inject
annotation in spring-test
@javax.inject.Inject
in spring-test
@javax.inject.Inject
in spring-test
@Inject
for autowiring test constructors
I've edited your comment to improve the formatting. You might want to check out this Mastering Markdown guide for future reference. |
Hi @FlorianLehmann, Congratulations on submitting your first PR for the Spring Framework! 👍
That's not entirely true. The Spring TestContext Framework supports whatever DI annotations are supported by Thus, you are free to use The only restriction regarding In addition, If I recall correctly, the latter is the reason that we decided not to support However, we will consider adding support for |
Hi @sbrannen,
Thank you I'll definitely have a look.
I believe the same limitation applies for "normal" constructor or method arguments. The idea of this PR is to remove the discrepancy between tests and "normal" code when autowiring a constructor using
👍 Thank you again for your comments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the proposal looks good in general, though I might revise it a bit after merging into main
.
This has been merged into Thanks for your contribution, @FlorianLehmann! 🍃 |
Overview
Spring 3.0 added support for JSR-330. However, the
spring-test
module is only supporting@Autowired
for dependency injection.This PR intends to add
@Inject
support forspring-test
. Since Spring Framework 6 still supports@javax.inject.Inject
in addition to@jakarta.inject.Inject
, this PR reintroduces support for@javax.inject.Inject
inspring-test
as well.Examples
The following test passes:
However, if
@Autowired
is replaced with@javax.inject.Inject
the test fails:Error