-
Notifications
You must be signed in to change notification settings - Fork 116
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
Clarify the required behaviour of @ConfigProperties beans #762
Comments
Yes, I agree that I also think that From the SmallRye Config side, we preferred to support something more like SmallRye Config |
That's not exactly what I said...
One doesn't have to. I mean it's not part of the spec. Why not simply delete that testcase from the TCK and make having field initializers undefined behaviour? Think about it this way: Except from the ability to use the same class with multiple prefixes, conceptually
and
should work more or less the same, right? In the second bean, you certainly could have field initializers. They just wouldn't do anything, because the field values would get overridden when injection happens. So why not ignore them altogether? As for supporting only interfaces... I think I'm coming around to this point of view the longer I think about the edge cases of the class based approach. On the other hand: I'd very much like records to be supported in the future as well. |
Looking at it again, the TCK testcase is fundamentally broken, even if we were of the opinion that |
Sure, they could be ignored, but what if you have a field initialized, but there is no configuration for that property name? For configurations not found, we fail the config. Should we fail in this case? I see arguments for both cases, but I feel it would look weird failing because there is no value for that field, when it was initialized directly.
We had that experience with Quarkus, since initially, we were also using the class base approach and it proved to be too troublesome, so we switched to the interface approach. Unfortunately, our experience was not enough to convince this group. It does seem that in Jakarta Config, the group came around and now supports the interface approach. I did write a discussion about this: jakartaee/config#122. We never even considered records, because of the language level in MP.
I think we should propose removing this particular test in the TCK. |
Why? That's just how CDI-stuff works, isn't it? If annotate a field with
Great. Where do I sign? |
In one of the cases you posted: @Dependent
@ConfigProperties(prefix="server")
class Server {
String host;
int port;
} You don't need any
Just submit a PR with the change :) |
…cases, because they are fundamentally broken; see issue microprofile#762
What I meant was: The Pull request is created. |
Catching with this thread. First of all, the bean can be any scoped. |
But that is against the CDI Spec as I understand it. To use the |
I think the spec is not clear about request-scoped beans (even for Should it reread all config values? This could lead to inconsistencies and expensive operations on each request to retrieve the Config. If it is just returning a new instance per request but with the same values, there is not much point. |
Scopes other than
to
And that's certainly a valid use case to me. However, maintaining my view point above that the two beans should be indistinguishable unless there are multiple prefixes in play, I expect a But it makes no sense to use such a bean with multiple prefixes. It's not even possible to implement that (without dropping the |
I agree that We looked in the spec and even the TCK and were not able to find a clarification, so we believe that a programmatic CDI lookup to a |
The Spec does not explicitly state what kind of CDI Bean a class annotated with
@ConfigProperties
should give rise to. The way I understand it, it MUST be a dependent bean. My reasons are:@Dependent
prefix
attribute in@ConfigProperties
is@NonBinding
. That means that the two example injection pointsand
are expected to resolve to the same bean. The only way the CDI spec allows for one bean to create two different instances depending on the injection point is for the bean to be
@Dependent
scoped.3. Programmatic lookup with arbitrary prefixes only works if it is a
@Dependent
bean for the same reason.HOWEVER: In the TCK there is a test with a
@RequestScoped @ConfigProperties
bean.The only way for a normal scoped bean to give different instances for different injection points is to have the
prefix
attribute be binding again. And in fact, that is what smallrye does: It removes the@NonBinding
annotation duringBeforeBeanDiscovery
and creates many, many synthetic beans from one@ConfigProperties
class - one for each prefix that is discovered at injection points. And all of them are@Dependent
scoped, even though the class specified@RequestScoped
. This feels like cheating.But that has another consequence: Programmatic lookup of
@ConfigProperties
no longer works as I would expect it. Again, the spec is not 100% clear here. The only example given isDoes that mean that this is the only case of programmatic lookup that is required to work? Or is it required that programmatic lookup with arbitrary prefixes works? I would have expected the latter to be the case (and indeed I have filed this as a smallrye bug )
The same TCK case also contains the bean
and the way it is used in the test case suggests that the field initializer replaces the need for a default value.
Where does this requirement come from? I cannot find it in the spec. And it is ... let's say weird ... from an implementation stand point. I tried to find the place where this is implementation in smallrye and could not find it. Maybe it is very well hidden, maybe smallrye just accidentally satisfies this testcase?
The text was updated successfully, but these errors were encountered: