这是我的bean试图注入一个单例bean InformationService:
@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);
}
}
Run Code Online (Sandbox Code Playgroud)
这是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;
}
}
Run Code Online (Sandbox Code Playgroud)
它是一个非常简单的JAX-RS实现的一部分,我正在JBoss 6.1 Final中作为战争部署.问题是当我发出正确的get请求时,InformationService会抛出NullPointerException.如果我明确初始化appService,一切正常.为什么@EJB注释不起作用?
| 归档时间: |
|
| 查看次数: |
1372 次 |
| 最近记录: |