glassfish给出了一个非法的例外 - 尝试部署java ee计时器应用程序

时间:2013-06-10 23:03:20

标签: java-ee-6

我有一个简单的应用程序。只有一个带有@startup和@singleton注释的EJB。它programmitcally创建一个计时器,并有一个@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)

1 个答案:

答案 0 :(得分:0)

我重启服务器几次,错误不再发生。还是不确定出了什么问题。我有一个跟进问题。我将@Resource更改为@inject并且它因javax.ejb.CreateException而失败:Singleton TimerSessionBean的初始化失败。有什么不同?我认为应该尽可能使用@inject?谢谢大家。