我有一个简单的应用程序。只有一个带有@startup 和@singleton 注解的EJB。它以编程方式创建一个计时器并具有一个@timeout 方法。代码主要来自 oracle 网站上的 java ee 6 教程。这是代码:
import java.util.logging.Logger;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.ejb.Timeout;
import javax.ejb.Timer;
import javax.ejb.TimerService;
@Singleton
@Startup
public class TimerSessionBean {
@Resource
TimerService timerService;
long duration = 6000;
private Logger logger = Logger.getLogger(
"simpletimer.service.TimerSessionBean");
@PostConstruct
public void setTimer() {
logger.info("Setting a programmatic timeout for "
+ duration + " milliseconds from now.");
Timer timer = timerService.createTimer(duration,
"Created new programmatic timer");
}
@Timeout
public void programmaticTimeout(Timer timer) {
logger.info("Programmatic timeout occurred.");
}
}
这是 serverlog 文件中的错误:
SEVERE: Exception while invoking class com.sun.enterprise.web.WebApplication start method
java.lang.Exception: java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: java.lang.IllegalArgumentException: javax.servlet.ServletException: com.sun.enterprise.container.common.spi.util.InjectionException: Error creating managed object for class: class org.jboss.weld.servlet.WeldListener
at com.sun.enterprise.web.WebApplication.start(WebApplication.java:138)
at org.glassfish.internal.data.EngineRef.start(EngineRef.java:130)
at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:269)
at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:301)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:461)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)
at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:389)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:348)