When I run my project, Spring invoke PostConstruct
mehod of JSF Action Bean
method at deployment time (during of spring bean creation, I think).
As I thought, there is no FacesCOntext
at deployment time, I get NullPointerException
at PostConstruct
method.
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() {
}
}
How can resolve it?
Just don't let Spring
to create a bean of AddStudentActionBean
class. I mean, there is no meaning of doing it. CDI
container will create and manage AddStudentActionBean
bean when its needed.
Generally you will like to create Service
or DAO
beans in Spring
's context.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.