-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Validator doesn't inject CDI bean unless @ApplicationScoped #6094
Comments
@gsmet maybe we can implicitly add make validator an application scoped bean implicitly by just detecting the implementations of |
I don't know. I did that at first when playing with HV + CDI and decided against it to avoid creating unnecessary beans as CV can also just be very simple classes with no injection. I wasn't sure making them all beans was a good solution. But there's one thing for sure, you need at least one scope annotation to make it a bean. Isn't it something expected in CDI? |
@gsmet I agree on avoiding the creation of unnecessary beans. Maybe that could be done as analysis during build time (whether things like injection are actually required). However, in order to Also this is a common pattern that I see in projects, so it would definitely help migrating code to Quarkus (especially since there is no error, the injection point is simply |
Any updates on this? Happy to help, btw. |
Well, it's normal the injection point is null. Your CV is just not a bean. If you want to give it a shot, we would need something similar to: https://github.com/quarkusio/quarkus/blob/master/extensions/resteasy-server-common/deployment/src/main/java/io/quarkus/resteasy/server/common/deployment/ResteasyServerCommonProcessor.java#L335 in the Hibernate Validator extension to add a scope automatically to classes extending |
@sdaschner once #11350 is in, could you make the same thing for Thanks! |
@gsmet Sure, done. Happy that I could finally help with something on the build process :) |
Describe the bug
A bean validator doesn't
@Inject
an application-scoped CDI bean if the validator itself is not@ApplicationScoped
.While it's described on https://quarkus.io/guides/validation that
validators are recommended to be application-scoped it doesn't read that
it's a requirement. There is no error, the bean is simply
null
.Expected behavior
Same behavior as in stock EE 8 runtime with JAX-RS, Bean Validation & CDI: injection works without making the validator application-scoped.
While it's helpful that the documentation points out the scope, it would help developers who have experience in plain Enterprise Java to migrate to Quarkus.
To Reproduce
Steps to reproduce the behavior:
@ValidOrder
).isValid()
is invoked, butshop
isnull
which results in a NPE.OrderValidator
with@ApplicationScoped
resolves the issue.Environment (please complete the following information):
uname -a
orver
:Linux archlinux 5.3.11-arch1-1 #1 SMP PREEMPT Tue, 12 Nov 2019 22:19:48 +0000 x86_64 GNU/Linux
java -version
:openjdk version "13.0.1" 2019-10-15 \n OpenJDK Runtime Environment AdoptOpenJDK (build 13.0.1+9) \n Eclipse OpenJ9 VM AdoptOpenJDK (build openj9-0.17.0, JRE 13 Linux amd64-64-Bit Compressed References 20191021_96 (JIT enabled, AOT enabled)
The text was updated successfully, but these errors were encountered: