プールにステートレスBeanが作成されたときに、タイマーEJB3を作成したいと思います。しかし、使用する@PostConstruct
と例外が発生します。
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を呼び出す場合、Beanはnullではありません。では、なぜこの例外が発生するのですか?
クラス
@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() {
}
}
インターフェース
@Local
public interface TesteLocal {
void test();
}
サーブレット
public class TestServlet extends HttpServlet {
@EJB
private TestLocal test;
protected void doGet(....) throws .... {
test.test();
}
}
詳細
weblogicサーバー11gを使用しています。