I am new to EJB technology and I am currently reading the Oracle Guide trying to put into practice what I read. I have created to this effect a simple JSF application in Eclipse with JBoss application Server, using a Managed Bean as backing Bean. I want to initialize the data in the Managed Bean by the aid of a Singleton Bean, just to feel how Dependency Injection works. I follow the relevant instructions, but I cannot manage to initialize the Singleton Bean. The application throws a NPE in the constructor of Hello Managed Bean. I anticipate that my code probably lacks something but I cannot find out it. Where is the defect in the following Bean classes? :
@Startup
@Singleton
public class LaunchBean {
private List<String> custs;
public List<String> getCusts() {
return custs;
}
public void setCusts(List<String> emps) {
this.custs = emps;
}
@PostConstruct
void init() { //in the guide the () after init is missed, but the code does not compile when omitting it
custs = new ArrayList<String>();
custs.add("Cust1");
custs.add("Cust3");
custs.add("Cust2");
custs.add("Cust4");
}
}
@ManagedBean
@SessionScoped
public class Hello implements Serializable{
@EJB
private LaunchBean dBean;
private static final long serialVersionUID = 1L;
private List<String> customers;
private String customersSelect;
public Hello(){
customers = dBean.getCusts();
}
public List<String> getCustomers() {
return customers;
}
public String getCustomersSelect() {
return customersSelect;
}
public void setCustomersSelect(String customersSelect) {
this.customersSelect = customersSelect;
}
}