Java JSF2.0CDI&x2B;Spring 3.1集成,FacesContext在部署时为空
当我运行我的项目时,Spring在部署时调用Java JSF2.0CDI&x2B;Spring 3.1集成,FacesContext在部署时为空,java,spring,jsf,Java,Spring,Jsf,当我运行我的项目时,Spring在部署时调用PostConstructJSF动作Bean方法(我认为是在springbean创建期间) 正如我所想,在部署时没有FacesCOntext,我在PostConstruct方法中得到NullPointerException import javax.inject.Named; import org.omnifaces.cdi.ViewScoped; @Named @ViewScoped public class AddStudentActionB
PostConstruct
JSF动作Bean方法(我认为是在springbean创建期间)
正如我所想,在部署时没有FacesCOntext
,我在PostConstruct
方法中得到NullPointerException
import javax.inject.Named;
import org.omnifaces.cdi.ViewScoped;
@Named
@ViewScoped
public class AddStudentActionBean implements Serializable {
private Student student;
@PostConstruct
public void init() {
student = (Student) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("Student");
}
@PreDestroy
public void destory() {
}
}
如何解决呢 不要让
Spring
创建AddStudentActionBean
类的bean。我的意思是,这样做没有意义CDI
容器将在需要时创建和管理AddStudentActionBean
bean
通常,您希望在
Spring
的上下文中创建Service
或DAO
bean。如果是这样,我不能omnifaces
的ViewScoped
。您仍然可以使用omnifaces的@ViewScoped
,因为这个bean是由CDI容器管理的,而不是Spring
。没有EJB,Spring,我可以使用@Name
?当然可以,javax.inject的@Named.Named
是一个CDI注释。与Spring或EJB无关。JSF说找不到addStudentActionBean
ActionBean