-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Support the Concept of @ActiveProfile from Spring CDI #6814
Comments
I like the idea but there are some problems we would need to resolve first:
@dmlloyd @emmanuelbernard Any ideas? |
I've see the Zulip discussion yesterday.
I agree this is the problematic part. Couldn't we "cheat it" by making the new annotation ( |
In that case the injection points would have to declare the qualifier as well... |
Not sure I follow.., the typesafe resolution says the bean is assignable if it has all the qualifiers that the injection point requires. Surplus qualifiers don't matter - just like we handle it with |
Well, if an injection point has no qualifier then it's defaulted ->
Indeed, because this would result in an ambiguous exception if multiple beans of the given type exist. It's mostly used for |
Aah, I see what you mean! That's a fair point, I forgot about default... |
Merging with the existing quarkus profiles concept makes sense to me. A user on Zulip was using the profiles manager to get the current profile and use it to drive a switch statement in a dynamic producer method, so there there is evidence users already come to this conclusion. it seems to me that the core issue here is that @QuarkusTest MUST spin up the whole context and there is no notion of multiple contexts. I’m not a CDI expert, but that seems limiting as a long time spring user. That said, I realize the trade off here with build time resolution. Perhaps in the short term documentation is the solution? The approach I came to feels pretty solid and basically achieves the same effect as profiles, but within existing CDI / quarkus annotations. If reading the config guide or a google search would have yielded my strategy , it would have saved me 2 days of frustration and nearly removing CDI entirely from the app. |
Would you care to send a PR? ;-) The testing guide: https://github.com/quarkusio/quarkus/blob/master/docs/src/main/asciidoc/getting-started-testing.adoc |
@mkouba I'd love to, but unclear when I could make it a priority. I’ll circle back on this next week. |
In #8343 we added |
Description
Spring Profiles are very different than Quarkus Profiles. The former is focused on decomposing your DI config into subsets, and the later is focused on environment specific config properties.
The most useful part of Spring Profiles is the ability to annotate a test with
@ActiveProfile("SomeProfile")
, which will instruct the DI system to only spin up beans with that profile. This is very helpful for tests written against an API, e.g. JPA. I may have two profiles "postgres" and "hsql", and depending on the test, I will want to spin up one or the other, but not both. Today's@QuarkusTest
will spin up the entire CDI config and there is no way to spin up a subset. User must use@ApplicationScoped
for lazy evaluation.You can kind of assemble this "Profile" concept using CDI qualifiers like
@Named
and@Typed
and@Alternative
, but it would be really nice to have@Profile
and@ActiveProfile
as first order concepts.See discussion in https://quarkusio.zulipchat.com/#narrow/stream/187030-users/topic/configuring.20Mocks.20in.20.40QuarkusTest
Implementation ideas
It would be nice to have this added as an ArC extensions like the CDI oriented convenience features in ArC. The Spring DI extension would work as well.
The text was updated successfully, but these errors were encountered: