Enabling EJB Injection into Vaadin 7 UI via Usage of Vaadin-CDI-Integration Addon

本小妞迷上赌 提交于 2019-12-20 04:18:05

问题


I wasn't able to successfully integrate the official Vaadin-CDI-Integration-Addon, since after finishing the official integration instructions, the following Exception was thrown in case I reloaded the already published URL localhost:8080/App/?restartApplication.

javax.servlet.ServletException: com.vaadin.server.ServiceException: 
java.lang.IllegalStateException: UI id has already been defined

The following little workaround is a tested, working solution, which completes the official instructions.


回答1:


You have to work off the following steps to successfully integrate the official CDI-Integration-Addon into your Vaadin project.

  • Do exactly as stated in the official how-to.
  • Remove the ?restartApplication parameter from the URL. This avoids the Exception.
  • Inject the EJB as shown in the listing below.
  • Keep in mind to restart your application manually if necessary!

@CDIUI
public class ExampleCDIUI extends UI {

    @Inject
    MyLocalBeanInterface myBean;

    @Override
    public void init(VaadinRequest request) {
        Label label = new Label("Hello Vaadin user");
        setContent(label);

        // myBean should be accessible now.

    }

}

That's it. I hope this helps :-)



来源:https://stackoverflow.com/questions/17929089/enabling-ejb-injection-into-vaadin-7-ui-via-usage-of-vaadin-cdi-integration-addo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!