ServerletContextListener 中的依赖注入
我正在使用 Weblogib BEA 10.0 应用程序服务器。
我想将 StatelessSessionBean 注入 ServletContextListener 中。 该 bean 应该做的就是启动一个定期计时器来执行清理任务。
我的项目分为 3 个工件。
首先有一个包含 ServletContextListener 的 war 文件:
public class ContextListener implements ServletContextListener {
@EJB(mappedName = "ejb/cleanUpTimer")
private CleanUpTimer cleanUpTimer;
public void contextInitialized(ServletContextEvent event) {
cleanUpTimer.activateCleanUpTimer();
}
}
第二个工件是一个包含 EJB 接口的公共库(jar 文件):
public interface CleanUpTimer {
public void activateCleanUpTimer();
}
第三个工件是一个包含 StatelessSessionBean 的 jar:
@Stateless(mappedName = "ejb/cleanUpTimer")
public class TimedCleanUpSLSB implements CleanUpTimer {
@Resource
private TimerService timerService;
public void activateCleanUpTimer() {
this.timerService.createTimer(timeout, timeout, "Clean Up Timer"); }
@Timeout
@TransactionAttribute(TransactionAttributeType.NEVER)
public void timedSessionCleanUp(Timer timer) {
// do something ...
}
}
当我部署应用程序时,容器注入“ null”到 ServletContextListener。
谁能帮我解决这个问题吗?
i'm working with a Weblogib BEA 10.0 app-server.
I want to inject a StatelessSessionBean into a ServletContextListener.
All this bean should do is start a periodic timer for clean up tasks.
My project is divided into 3 artifacts.
At first there is a war-file containing the ServletContextListener:
public class ContextListener implements ServletContextListener {
@EJB(mappedName = "ejb/cleanUpTimer")
private CleanUpTimer cleanUpTimer;
public void contextInitialized(ServletContextEvent event) {
cleanUpTimer.activateCleanUpTimer();
}
}
The second artifact is a common library (jar-file) containing the interface of the EJB:
public interface CleanUpTimer {
public void activateCleanUpTimer();
}
The third artifact is a jar containing the StatelessSessionBean:
@Stateless(mappedName = "ejb/cleanUpTimer")
public class TimedCleanUpSLSB implements CleanUpTimer {
@Resource
private TimerService timerService;
public void activateCleanUpTimer() {
this.timerService.createTimer(timeout, timeout, "Clean Up Timer"); }
@Timeout
@TransactionAttribute(TransactionAttributeType.NEVER)
public void timedSessionCleanUp(Timer timer) {
// do something ...
}
}
When i deploy the application the Container injects "null" to the ServletContextListener.
Can anyone help me with this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论