2012-02-07 7 views
5

を登録なっているが、別のステートレスBeanの内部に注入得ていないシングルトンBeanはInformationServiceシングルトン豆を注入しようとしている私のBeanです:EJB 3.1:両方の豆はここ

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

これはInformationServiceですクラス

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

} 

非常にシンプルなJAX-RS実装の一部であり、私はJBoss 6.1 Finalで戦争として展開しています。問題は、適切なget要求を行うとInformationServiceがNullPointerExceptionをスローすることです。 appServiceを明示的に初期化すると、すべて正常に動作します。 @EJB注釈が機能しないのはなぜですか?

答えて

0

JerseyをREST実装として使用していますか?その場合、EJBインジェクションはそのままではサポートされていません。

This linkは、これと解決策についての詳細情報を提供します。

+0

JBossのJAX-RS実装(RestEasyではなく)を使用しています。 – Daud

0

@Singletonがjavax.ejb.Singletonであることを確認してください。 NPE以前の例外はありますか?

関連する問題