I have an application with several WEB modules and an EJB within an EAR according to the following image:
IntheEJBmoduleIcreatedanannotatedclasswith@ApplicationScoped
,mygoalisforthisclasstostoreinformationthatmustbepassedbetweentheWEBprojects.IthappensthatwhenaddinginformationintheclassintheprojectPortalTreinamentosWEBtheyarenotvisibleintheprojectModuleAlunoforexample.
Hereisthecodefortheclassthatisannotatedwith@ApplicationScope
@ApplicationScopedpublicclassServiceAutenticacao{privateMap<String,Colaborador>mapaTickets=newHashMap<String,Colaborador>();publicServiceAutenticacao(){System.out.println("Objeto service Autenticação criado...........................");
}
public void adicionaColaborador(String ticket, Colaborador colaborador){
this.mapaTickets.put(ticket, colaborador);
}
public Colaborador getColaborador(String ticket) throws ServiceException{
if(mapaTickets.containsKey(ticket)){
return mapaTickets.get(ticket);
}else{
throw new ServiceException("Ticket de autenticação inválido: " + ticket);
}
}
}
It follows that I write information on the object of this class in the project PortalTreinamentosWEB:
@ManagedBean
@SessionScoped
public class PrincipalController {
@Inject private ServiceAutenticacao serviceAutenticacao;
public void redirecionaModuloAluno(){
//pendura o colaborador com um ticket no Servico de Autenticação entre projetos
String ticketInterno = UtilService.generateOid();
this.serviceAutenticacao.adicionaColaborador(ticketInterno , this.colaboradorAutenticado);
HttpServletRequest req = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
String url = req.getRequestURL().toString();
String urlModuloAluno = url.substring(0, url.length() - req.getRequestURI().length()) + "/ModuloAluno/autenticacao/autenticacao.jsf?ticketinterno="+ticketInterno;
FacesContext context = FacesContext.getCurrentInstance();
try {
context.getExternalContext().redirect(urlModuloAluno);
} catch (IOException e) {
e.printStackTrace();
}
}
And as I try to get this information in the module ProjectAluno:
@ManagedBean
@RequestScoped
public class AutenticacaoController {
@Inject private ServiceAutenticacao serviceAutenticacao;
Colaborador colaborador = serviceAutenticacao.getColaborador(this.ticketInterno);
System.out.println("Colaborador: " + colaborador.getNome());
principalController.setColaboradorAutenticado(colaborador);
I put a System.out in the constructor of class ServiceAutenticacao
and realized that it is being instantiated several times.
So my question is, is the object annotated with @ApplicationScope
the same among several projects of the same EAR?
If so, could you tell me why I can not access the information in the other project ( ModuloAluno
)