2013-10-30 27 views
0

我在JBoss AS 7.1.1中有一个应用程序,并且想要使用TimerService。我注入它正是如此:无法注入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 

我曾尝试几种其它方法,包括注入SessionContext或使用查找()上一个InitialContext来获取SessionContext,但它们都会遇到基本相同的问题。

我在这里错过了什么?

+0

你正在部署什么样的应用程序? (ear/war)以及什么是TimerService的全限定类名? –

回答

1

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

@Singleton 

到bean的声明,它现在起作用。