bean discovery mode

Hi everyone,
i was doing the cdi-vaadin tutorial and i think there are serveral issues very important that the tutorial doesn’t mention.
I use wildfly as server.

1 - The file beans.xml is mandatory if you intend to use cdi.
2 - You must use bean discovery mode “all” and not “annotated” in the bean.xml file

If you use annotated the server:

  • Doesn’t recognize the vaadin-cdi beans (@UIScoped, …)
  • You must write @Dependent (this is the default scope in CDI specification).

Thanks for the important suggestions. Let’s see if I can get someone to update that tutorial. It seems to need some revising anyways. And just to make sure? You mean this tutorial:
https://vaadin.com/wiki/-/wiki/Main/Vaadin+CDI

EDIT: Language

Yes this is the tutorial.
Well, the tutorial use another server TomEE ( wildfly needs beans.xml (even if it is empty) ).
The discovery mode is a little bizarre but explain differents behaviour of scanning the beans cdi.
I’m a begginner, i just only get an explanaition (but i supposed this questions are to Wildfy Forum in JBoss web).

It 's normal the out of date in a tutorial with it is made two years ago (it is mentioned in the tutoria).
PD:
English is not my maternal language so it is weird for me when you said… it seems to need some love???

I edited my answer to make the language less metaphorical.

The topic is outdated but its worth exploring this. I am using Vaadin 25.2 with Wildfly.

I wanted to use “annotated” option for the bean-discovery-mode inside bean.xml.
In order to trigger PostConstruct method to work, I would need to use at least Depndent annotation. However, in that case I am unable to use Vaadin RouteScoped anymore as it leads to error during deployment caused by multiple scope annotations over component

“At most one scope may be specified on [EnhancedAnnotatedTypeImpl]”

Below is the implementation that I am using with annotated option. This implementation does not trigger @PostConstruct method on Wildfly.

@Route("/prs")
@CdiComponent
@RouteScoped
public class PersonaView extends VerticalLayout {
    
    private static final Logger LOG = LoggerFactory.getLogger(PersonaView.class);
    
    @Inject
    private MyCdi cdi;
    
    @PostConstruct
    public void test() {
        LOG.info("PersonaView init");
    }
    
    public PersonaView() {
        var x = new Button("test");
        x.addClickListener(_ -> cdi.test());
        add(x);
    }
}

The only workarounds I have found are:

  1. to use bean-discovery-mode=“all” which is discouraged practice.
  2. Use CdiComponent, Dependent but I suspect this will create problems inside the framework due to lack of Vaadin scope.

Is there a way I can use bean-discovery-mode=“annotated” together with Vaadin scope annotations so that I can trigger PostConstruct method?

You could compare your project to my Java EE CDI demo

Writing code to be compliant with annotated bean discovery requires some care, but it should work.

Thank you very much for sharing these demos with me.

In short using CdiComponent with Dependent works nicely but yes, this will need care.