在企業應用程序中,我試圖使用netBeans 8.1將MessageDriven bean注入到Web應用程序(到REST服務)。我不明白IDE中的任何警告,但是,在部署時,我收到以下錯誤:注入消息驅動bean
嚴重:異常而加載的應用程序:CDI部署失敗:WELD-001408:類型StatisticsBean不滿意的依賴與預選賽@default 於注射點[BackedAnnotatedField] @注入私人sv.mycompany.rest.RestService.statisticsBean
這裏是豆類我試圖注入之一:
@MessageDriven(mappedName = "dzsobTopik")
public class StatisticsBean implements MessageListener{
private Logger LOGGER = Logger.getLogger(StatisticsBean.class.getSimpleName());
private int scheduledJobs = 0;
@Inject
private JMSContext jmsContext;
private static Map<Integer, Boolean> results = new HashMap<>();
public StatisticsBean() {
}
public static Map<Integer, Boolean> getResults() {
return results;
}
public void setResults(Map<Integer, Boolean> results) {
StatisticsBean.results = results;
}
@Override
public void onMessage(Message message) {
if(message instanceof JobScheduledMessage){
scheduledJobs++;
}
else if(message instanceof JobCompletedMessage && scheduledJobs>0) {
if(((JobCompletedMessage) message).getTimestamp()<5){
LOGGER.log(Level.INFO, "Job successful!");
results.put(((JobCompletedMessage) message).getJobnumber(), Boolean.TRUE);
scheduledJobs--;
}
else {
LOGGER.log(Level.INFO, "Job unsuccessful!");
results.put(((JobCompletedMessage) message).getJobnumber(), Boolean.FALSE);
scheduledJobs--;
}
}
}
}
這裏是我的restService類:
@Path("/start")
@Produces(MediaType.APPLICATION_JSON)
public class RestService {
@Inject
private JobScheduler jobScheduler;
@Inject
private StatisticsBean statisticsBean;
@Inject
private FastWorker fastWorker;
@Inject
private SlowWorker slowWorker;
@Inject
private NormalWorker normalWorker;
@GET
@Produces(MediaType.TEXT_PLAIN)
public String startSimulation() throws InterruptedException{
jobScheduler.queueNewJobs();
return "Started simulation";
}
@GET
@Path("/jobresult")
public Map<Integer,Boolean> getJobResults(){
return StatisticsBean.getResults();
}
}
我在ejb和web模塊中都有beans.xml,在這兩種情況下發現模式都設置爲「all」。可能是什麼問題呢?
可能重複的[EJB3 - 注入MDB到另一個MDB?](http://stackoverflow.com/questions/8246963/ejb3-inject-a-mdb-into-another-mdb) –