如何在启动时执行此EJB方法?

时间:2017-02-06 10:07:51

标签: java-ee ejb-3.1

我在这里不知所措。除了所有外部因素,这是一个EJB假设 在Wildfly 8.2.1.Final上运行att部署,但Wildfly是不均匀的 调用构造函数,从Exception中可以看出,它永远不会被抛出。

bean正在初始化一个Timer,这应该重复一些 定期任务iven在配置文件中。所有这些都在Java中运行 SE环境,但它的大部分内容都被删除,以消除对问题的干扰。

package jollobajano.bedtime.service.cleanupdaemon;

import javax.annotation.Resource;
import javax.ejb.ScheduleExpression;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.ejb.Timeout;
import javax.ejb.Timer;
import javax.ejb.TimerService;
import javax.inject.Inject;

import org.slf4j.Logger;

import jollobajano.bedtime.service.cleanupdaemon.config.CronExpression;
import jollobajano.bedtime.service.cleanupdaemon.config.JobConfiguration;
import jollobajano.bedtime.service.cleanupdaemon.config.ProducedConfig;
import jollobajano.bedtime.service.cleanupdaemon.config.ScheduleExpressionProvider;

@Singleton
@Startup
public class ScheduledCleanupBean {

    @Inject
    private Logger log;

    private Timer timer;

    @Inject
    @ProducedConfig
    private JobConfiguration configuration;

    @Inject
    private ScheduleExpressionProvider scheduleExpressionProvider;

    @Resource
    private TimerService timerService;

    public ScheduledCleanupBean() {
        System.err.println("### Constructing a ScheduledCleanupBean ### MATS");
        if (true) {
            throw new IllegalStateException("This is supposed to work, no?");
        }
    }

    @javax.ejb.PostConstruct
    public void init() {
        System.err.println("### Initializing a ScheduledCleanupBean ### MATS");
        if (configuration != null) {
            CronExpression cron = configuration.getCron();
            ScheduleExpression schedule = scheduleExpressionProvider.getScheduleExpression(cron);
            timer = timerService.createCalendarTimer(schedule);
            log.info("{} initialised.", this.getClass().getName());
        } else {
            log.info("{} not initialised. No configuration file found.", this.getClass().getName());

        }
    }

    @javax.ejb.PreDestroy
    public void exit() {
    }

    @Timeout
    public void execute(Timer timer) {
        for (String select : configuration.getSelect()) {
            log.info("SELECT: {}", select);
        }
    }

}

我不会厌倦整个日志,但它会在两个中提到 上下文,以便向我表明找到并注册了bean 在某些方面。

 of type org.hibernate.validator.internal.engine.resolver.JPATraversableResolver.
2017-02-06 10:37:28,052 DEBUG [org.jboss.as.ejb3.deployment.processors.ImplicitLocalViewProcessor] (MSC service thread 1-12) Bean: ScheduledCleanupBean will be marked for (implicit) no-interface view
2017-02-06 10:37:28,057 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-12) JNDI bindings for session bean named ScheduledCleanupBean in deployment unit deployment "bedtime2-application-2.0-SNAPSHOT.war" are as follows:

    java:global/bedtime2-application-2.0-SNAPSHOT/ScheduledCleanupBean!jollobajano.bedtime.service.cleanupdaemon.ScheduledCleanupBean
    java:app/bedtime2-application-2.0-SNAPSHOT/ScheduledCleanupBean!jollobajano.bedtime.service.cleanupdaemon.ScheduledCleanupBean
    java:module/ScheduledCleanupBean!jollobajano.bedtime.service.cleanupdaemon.ScheduledCleanupBean
    java:global/bedtime2-application-2.0-SNAPSHOT/ScheduledCleanupBean
    java:app/bedtime2-application-2.0-SNAPSHOT/ScheduledCleanupBean
    java:module/ScheduledCleanupBean

2017-02-06 10:37:28,135 DEBUG [org.wildfly.jberet] (MSC service thread 1-9) Creating batch environment; ModuleClassLoader for Module "deployment.bedtime2-application-2.0-SNAPSHOT.war:main" from Service Module Loader
2017-02-06 10:37:28,137 DEBUG [org.jboss.as.ejb3.deployment.processors.EjbClientContextSetupProcessor] (MSC service thread 1-14) Deployment unit deployment "bedtime2-application-2.0-SNAPSHOT.war" doesn't have any explicit EJB client context configured. Falling back on the default service jboss.ejb3.ejbClientContext.default EJB client context service
2017-02-06 10:37:28,137 DEBUG [org.jboss.as.ejb3.deployment.processors.EjbClientContextSetupProcessor] (MSC service thread 1-14) Registering EJB client context org.jboss.ejb.client.EJBClientContext@63a2929d for classloader ModuleClassLoader for Module "deployment.bedtime2-application-2.0-SNAPSHOT.war:main" from Service Module Loader
2017-02-06 10:37:28,137 DEBUG [org.jboss.as.ee] (MSC service thread 1-14) Configuring component class: org.apache.taglibs.standard.tlv.JstlFmtTLV named org.apache.taglibs.standard.tlv.JstlFmtTLV
2017-02-06 10:37:28,149 DEBUG [org.jboss.as.ee] (MSC service thread 1-14) Configuring component class: org.apache.struts2.dispatcher.ng.filter.StrutsPrepareFilter named org.apache.struts2.dispatcher.ng.filter.StrutsPrepareFilter
2017-02-06 10:37:28,152 DEBUG [org.jboss.as.ee] (MSC service thread 1-14) Configuring component class: org.apache.taglibs.standard.tag.el.core.WhenTag named org.apache.taglibs.standard.tag.el.core.WhenTag
2017-02-06 10:37:28,155 DEBUG [org.jboss.as.ee] (MSC service thread 1-14) Configuring component class: org.apache.struts2.views.jsp.ui.FileTag named org.apache.struts2.views.jsp.ui.FileTag
2017-02-06 10:37:28,161 DEBUG [org.jboss.as.ee] (MSC service thread 1-14) Configuring component class: org.apache.struts2.views.jsp.ui.AnchorTag named org.apache.struts2.views.jsp.ui.AnchorTag
2017-02-06 10:37:28,164 DEBUG [org.jboss.as.ee] (MSC service thread 1-14) Configuring component class: org.apache.struts2.views.jsp.ui.PasswordTag named org.apache.struts2.views.jsp.ui.PasswordTag
2017-02-06 10:37:28,166 DEBUG [org.jboss.as.ee] (MSC service thread 1-14) Configuring component class: org.apache.struts2.views.jsp.ui.SubmitTag named org.apache.struts2.views.jsp.ui.SubmitTag
2017-02-06 10:37:28,167 DEBUG [org.jboss.as.ee] (MSC service thread 1-14) Configuring component class: jollobajano.bedtime.service.cleanupdaemon.ScheduledCleanupBean named ScheduledCleanupBean
2017-02-06 10:37:28,198 DEBUG [org.jboss.as.ejb3] (MSC service thread 1-14) Security is *not* enabled on EJB: ScheduledCleanupBean, no security interceptors will apply
2017-02-06 10:37:28,204 DEBUG [org.jboss.as.ee] (MSC service thread 1-14) Configuring component class: org.apache.taglibs.standard.tag.el.fmt.FormatDateTag named org.apache.tag:

以后

2017-02-06 10:37:29,558 DEBUG [org.jboss.weld.Bootstrap] (MSC service thread 1-7) WELD-000106: Bean: Session bean [class jollobajano.bedtime.service.cleanupdaemon.ScheduledCleanupBean with qualifiers [@Any @Default]; local interfaces are []

我想这很容易被新鲜的眼睛所发现。有人看到我的错误吗?

干杯 垫

0 个答案:

没有答案