所以我试图创建一个定期触发的任务,我希望它从 ServletContext 中获取一些东西:
...
@Singleton
@Startup
public class InitTimers {
@Resource
private TimerService timerService;
@PostConstruct
public void initTimer() {
...
// I want ServletContext here, how do I?
ServletContext context = getServletContext();
...
}
@Timeout
public void timeout(Timer timer) {
...
}
}
EJB 3.1 @Startup @Singleton 可以访问 ServletContext 吗?