【发布时间】:2010-08-15 19:35:56
【问题描述】:
我想在池中创建无状态 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 server 11g。
【问题讨论】:
标签: java jakarta-ee ejb-3.0 weblogic weblogic11g