2012-02-07 14 views
5

Aquí es mi frijol que está tratando de inyectar un producto único grano de InformationService:EJB 3.1: frijol Singleton no conseguir inyecta dentro de otro bean sin embargo ambos granos que se registran

@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); 
    } 
} 

Ésta es la InformationService clase

@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; 
    } 

} 

Su parte de una manera muy sencilla aplicación JAX-RS y estoy desplegando como la guerra en JBoss 6.1 final. El problema es que InformationService lanzando una NullPointerException cuando realizo la solicitud get adecuada. Si inicializo appService explícitamente, todo funciona bien. ¿Por qué @EJB anotación no funciona?

Respuesta

0

¿Está usando Jersey como implementación de REST? Si es así, la inyección de EJB no se admite de fábrica.

This link proporciona más información sobre esto y también una solución.

+0

Estoy utilizando la implementación de JBoss de JAX-RS (no RestEasy) – Daud

0

Comprueba que tu @Singleton sea javax.ejb.Singleton. ¿Alguna otra excepción antes de NPE?

Cuestiones relacionadas