无法注入TimerService

时间:2013-10-30 15:13:47

标签: timer jboss ejb

我在JBoss AS 7.1.1中有一个应用程序,并且想要使用TimerService。我这么注射:

@Resource
private TimerService timerService;

在访问应用程序中的页面时,会出现以下错误:

16:08:30,471 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/c3e].[Faces Servlet]] (http--127.0.0.1-8080-2) Servlet.service() for servlet Faces Servlet threw exception: javax.naming.NameNotFoundException: env/myapp.mypackage.MyClass/timerService -- service jboss.naming.context.java.module.myapp.myapp.env."com.dpdhl.cac.c3e.etl.beans.Resources".timerService

我已经尝试了其他几种方法,包括在InitialContext上注入SessionContext或使用lookup()来获取SessionContext,但它们都遇到了基本相同的问题。

我在这里缺少什么?

1 个答案:

答案 0 :(得分:1)

问题解决了:我注入TimerService的bean必须是EJB,而不仅仅是CDI bean。我添加了

@Singleton

到bean的声明,现在可以正常工作。

相关问题