I have decided to migrate an application in the architecture JPA-EJB-JSF toward JPA-Spring-JSF.
During this migration to spring I have enabled CDI also.
After the migration of all the layers I am at the level of the layer of the controllers.
In Java EE I have annotated methods with @PostConstruct
which allow me to initialize variables,test configurations for the applied.These methods are running before before the setters/getters.
Example Java EE code:
@ManagedBean(name="classecontroller")
@SessionScoped
public class ClasseController implements Serializable {
private Etablissements etablissement;
private Classe classe = new Classe();
private Niveau niveau = new Niveau();
private Personne currentUser;
public ClasseController() {}
@PostConstruct
void initialiseSession() {
etablissement = new Etablissements();
Etablissements testEtab = null;
testEtab = (Etablissements) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get(GlobalFonctions.ETAB_ACTIF);
if (testEtab != null) {
etablissement = testEtab;
} else {
etablissement = (Etablissements) FacesContext.getCurrentInstance().getExternalContext().getApplicationMap().get(GlobalFonctions.ETAB_ACTIF);
}
}
// setter getters
}
After migration on Spring I have read that the @PostConstruct
is only executed after the initialization of the beans in the context.Therefore I have found that my methods that should be executed at the start of my application no longer run during the opening of a web page using my controller.
I would like to know how I can implement this without too many changes to the code?
here is the code Spring:
@Named("classecontroller")
@SessionScoped
public class ClasseController implements Serializable {
private Etablissements etablissement;
private Classe classe = new Classe();
private Niveau niveau = new Niveau();
private Personne currentUser;
public ClasseController() {}
@PostConstruct
void initialiseSession() {
etablissement = new Etablissements();
Etablissements testEtab = null;
testEtab = (Etablissements) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get(GlobalFonctions.ETAB_ACTIF);
if (testEtab != null) {
etablissement = testEtab;
} else {
etablissement = (Etablissements) FacesContext.getCurrentInstance().getExternalContext().getApplicationMap().get(GlobalFonctions.ETAB_ACTIF);
}
}
// setter getters
}
Thanks