Vaadin:引用后CDI注入为空 [英] Vaadin: CDI Inject is null after referencing
问题描述
美好的一天。
有一个应用程序(使用CDI插件):
There is an application (using a CDI add on):
@VaadinScoped(VaadinScope.APPLICATION)
public class AdminApplication extends AbstractCdiApplication {
@Inject
private Instance<Lang> lang;
@Override
public void init() {
setMainWindow(new LoginWindow(this));
}
public void authenticate(String login, String password) throws Exception {
lang.get(). ...
}
...
和LoginWindow:
And the LoginWindow:
public class LoginWindow extends Window {
...
public LoginWindow(AdminApplication application) {
super("LoginWindow Login");
this.application = application;
initUI();
initLoginListener();
}
private void initLoginListener() {
btnLogin.addListener(new Button.ClickListener() {
public void buttonClick(Button.ClickEvent event) {
try {
String username = (String) txtUsername.getValue();
String password = (String) txtPassword.getValue();
application.authenticate(username, password);
} catch (Exception e) {
showNotification(e.toString());
}
}
});
}
问题是当它是应用程序的初始化阶段时, lang.get()
不为null,但是在LoginWindow中,我调用 application.authenticate()
方法时, lang.get()
始终为null。似乎在使用引用时, Instance.get()
方法无法获取类的实例。
The problem is when it is the application's initialization phase the lang.get()
is not null, but when in the LoginWindow I call application.authenticate()
method, the lang.get()
is always null. It seem that when using a reference the Instance.get()
method can't get the class' instance.
有人知道为什么会这样吗?
Does anybody know why this happens?
推荐答案
我在Wildfly 8.1和8.2中遇到了这个问题,但是当我在WEB-INF中添加一个空的beans.xml时,它起作用了。因此,如果上述方法无效,请尝试一下。
I had this problem with Wildfly 8.1 and 8.2 but when I added an empty beans.xml in the WEB-INF it worked. So if the above doesn't work try that.
这篇关于Vaadin:引用后CDI注入为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!