Đây là đậu của tôi đang cố gắng tiêm một singleton đậu InformationService:EJB 3.1: Singleton đậu không nhận được tiêm bên trong một đậu quốc tịch mặc dù cả hai đậu đang nhận đăng ký
@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);
}
}
Đây là InformationService lớp
@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;
}
}
Phần thực hiện JAX-RS rất đơn giản và tôi đang triển khai như chiến tranh trong JBoss 6.1 Final. Vấn đề là InformationService ném NullPointerException khi tôi thực hiện yêu cầu nhận phù hợp. Nếu tôi khởi tạo appService một cách rõ ràng, mọi thứ hoạt động tốt. Tại sao chú thích @EJB không hoạt động?
Tôi đang sử dụng triển khai JBAX 'của JAX-RS (không phải RestEasy) – Daud