Ecco il mio fagiolo che sta cercando di iniettare un Singleton fagioli InformationService:EJB 3.1: Singleton fagioli non ottenere iniettato all'interno di un altro bean senza se entrambi i fagioli sono di iscriversi
@Path("/information/{name}")
@Stateless (name="InformationResource")
public class InformationResource {
@EJB
private InformationService appService;
@GET
@Produces(MediaType.APPLICATION_XML)
public Information getInfo(@PathParam("name") String name){
return appService.getMap().get(name);
}
@PUT
@POST
@Consumes(MediaType.APPLICATION_XML)
public Information putInfo(@PathParam("name") String name, Information info){
return appService.getMap().put(name,info);
}
@DELETE
public void deleteInfo(@PathParam("name") String name){
appService.getMap().remove(name);
}
}
Questa è la InformationService classe
@Singleton
public class InformationService {
private Map<String,Information> map;
@PostConstruct
public void init(){
map = new HashMap<String,Information>();
map.put("daud", new Information("B.Tech","Lucknow"));
map.put("anuragh", new Information("M.Sc","Delhi"));
}
public Map<String,Information> getMap(){
return map;
}
}
la sua parte di un molto semplice implementazione JAX-RS e sto schierando come guerra in JBoss 6.1 finale. Il problema è che InformationService lanciare una NullPointerException quando faccio la richiesta di ottenere corretta. Se inizializzo appService in modo esplicito, tutto funziona correttamente. Perché l'annotazione @EJB non funziona?
Utilizzo l'implementazione JBoss di JAX-RS (non RestEasy) – Daud