问题
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 theException
. - 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