OpenWebBeans throws NoSuchElementException java ee

47 Views Asked by At

I created the configuration of OpenWebBeans as indicated in the video tutorial, but for some reason I get a NoSuchElementException exception. Why can't I find Bean's name? How to fix it?

project structure

public class MyTag2{
    public static void main(String[] args) {
        ContainerLifecycle lifecycle = WebBeansContext
                .currentInstance().getService(ContainerLifecycle.class);
        lifecycle.startApplication(null);

        BeanManager beanManager = lifecycle.getBeanManager();
        Bean<?> bean = beanManager.getBeans("myBean").iterator().next();

        MyBean myBean = (MyBean) lifecycle.getBeanManager()
                .getReference(bean, MyBean.class, beanManager.createCreationalContext(bean));
        myBean.print();

        lifecycle.stopApplication(null);
    }
}


@Model
@Named("myBean")
class MyBean {
    public void print() {
        System.out.println("hello");
    }
}

0

There are 0 best solutions below