通过使用Vaadin-CDI集成插件,将EJB注入到Vaadin 7 UI中

问题描述:

我无法成功整合官方的Vaadin-CDI-Integration-Addon,因为在完成官方整合说明之后,以下异常被抛出,以防万一重新加载已发布的U​​RL localhost:8080 / App /?restartApplication

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.

您必须执行以下步骤才能将官方CDI-Integration-Addon成功整合到您的Vaadin项目中。

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 :-)