我想在池中創建一個無狀態bean時創建一個計時器EJB3。 但是,如果使用@PostConstruct
我得到異常:如何使用@PostConstruct在無狀態bean EJB3中創建定時器?
java.lang.IllegalStateException: [EJB:010193]Illegal call to EJBContext method. The bean is in "null" state. It cannot perform 'getting the Timer Service' action(s). Refer to the EJB specification for more details.
如果容器調用@PostConstruct,豆ins't空。那麼,爲什麼我得到這個異常?
CLASS
@Stateless
public class TestBean implements TestLocal {
@Resource
TimerService timerService;
@PostConstruct
public void startTimer() {
if (timerService.getTimers().size() == 0) {
timerService.createTimer(1 * 1000, 1 * 1000, null);
}
}
@Override
public void test() {
}
}
INTERFACE
@Local
public interface TesteLocal {
void test();
}
SERV LET
public class TestServlet extends HttpServlet {
@EJB
private TestLocal test;
protected void doGet(....) throws .... {
test.test();
}
}
詳情
我使用WebLogic服務器11g。
我按照你的例子做了2個改變:a)TestLocal有一個方法由TestBean實現(沒有這個,weblogic不能部署)b)創建一個調用EJB的servlet。錯誤仍然發生。 – Topera 2010-08-18 01:06:28
@Topera我真的不確定(我甚至不確定我的建議對於EJB 3.0是必須的)。我可能是錯的,但這看起來像一個錯誤。我建議聯繫支持 – 2010-08-19 21:21:12
呃....這是我唯一的答案.... + 1並且接受! :) – Topera 2010-08-20 12:57:09