我是Vaadin的新手,我正在尝试在我的UI类中注入@UIScoped
- bean。但它每次都会抛出NullPointerException
- 为什么?
这是我的UI类:
import javax.inject.Inject;
import org.apache.log4j.Logger;
import com.vaadin.annotations.Theme;
import com.vaadin.cdi.CDIUI;
import com.vaadin.server.VaadinRequest;
import com.vaadin.ui.Label;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
@SuppressWarnings("serial")
@Theme("tableuitheme")
@CDIUI("")
public class Table extends UI {
private final static Logger logger=Logger.getLogger(Table.class);
@Inject
private SomeBean bean;
@Override
protected void init(VaadinRequest request) {
VerticalLayout layout = new VerticalLayout();
setContent(layout);
logger.info("-------------------------- "+bean);
// String art = hakan.toString();
Label label = new Label("Hakan");
layout.addComponents(label);
}
}
这是界面SomeBean
:
public interface SomeBean {
}
和实现类SomeBeanImpl
:
import com.vaadin.cdi.UIScoped;
@UIScoped
public class SomeBeanimpl implements SomeBean {
}
最后是我的配置文件:
的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_0.xsd">
<servlet>
<servlet-name>myVaadinUIServlet</servlet-name>
<servlet-class>com.vaadin.server.VaadinServlet</servlet-class>
<init-param>
<param-name>UI</param-name>
<param-value>de.ragms.ui.Table</param-value>
</init-param>
<async-supported>true</async-supported>
</servlet>
<context-param>
<description>Vaadin production mode</description>
<param-name>productionMode</param-name>
<param-value>false</param-value>
</context-param>
<servlet-mapping>
<servlet-name>myVaadinUIServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
bean.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
</beans>