Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdi-dev] Empty beans.xml in CDI 4.0

Hello,

lately I have been thinking about discovery modes and the definition of bean archive WRT to empty `beans.xml` file.

For a long time we have been promoting the `annotated` discovery mode as opposed to `all` mode.
One of the reasons is plain efficiency as less classes are processed and less metadata is created and carried over into your application.
Another reason is that you avoid accidental ambiguous resolutions as classes you don't expect to become beans might be picked up as well.
Last but not least, user has to make a conscious decision about what beans they want and with what scope using annotations which is what CDI is about.

Currently, if you do not add `beans.xml` file at all, you end up with `annotated` mode which is fine.
However, adding empty `beans.xml` means discovery mode `all`.

I suggest that for the next major version we change this so that empty `beans.xml` == `annotated` mode.
Along with this there could be a config option that allows users to switch to previous behavior (we already have one such case in spec, see[1]).
Now, this is obviously a breaking change with the config making it viable for users to turn it off if they are not ready to adapt their app.
Here is why I think it is worth it:
a) It promotes the `annotated` mode over `all` which is a general recommendation for most projects
 - lots of projects are still adding empty `beans.xml` their settings (e.g. even if they use bean defining annotations)
b) Having this default would make a sensible ground for the ongoing CDI Lite efforts and it's bean discovery while keeping it compatible with Full CDI
 - basically, it would solve the problems we discussed in several mailing thread (see long thread [2] and another post here[3])
 - Lite could require presence of beans.xml but it could stay empty and still be portable between both CDI variants

Like I stated before, this would be a breaking change.
OTOH, it is a way forward that accommodates both, CDI Lite and Full in a portable manner.
Thoughts? Ideas?

Regards
Matej
______________________________________________________________
[1] https://jakarta.ee/specifications/cdi/2.0/cdi-spec-2.0.html#bean_archive
[2] https://www.eclipse.org/lists/cdi-dev/msg00180.html
[3] https://www.eclipse.org/lists/cdi-dev/msg00275.html



Back to the top