我想在池中创建无状态 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 不为空。那么,为什么我会得到这个异常?
班级
@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。