1 Reply Latest reply on Jun 29, 2010 10:19 PM by Nikolay Elenkov

    Quartz, Application Scope, Injection

    Kyle Thielk Newbie


      I am setting up a quartz job to run in the background of my application. I can get the simple job to run just fine until I need to do anything generally conversation scoped in Seam.  Here are my files:

      @Name( "statusScheduleController" )
      @Scope( ScopeType.APPLICATION )
      @Startup( depends =
          } )
      public class StatusScheduleController
          private QuartzTriggerHandle quartzTriggerHandle;
          @In( value = "statusSheduleProcessor")
          private StatusScheduleProcessor processor;
          private static final String KEY_STATUS_SCHEDULE_CRON_INTERVAL = "status.schedule.cron.interval";
          public void startup()
                  String cronInterval = PropertyUtil.getProperty( KEY_STATUS_SCHEDULE_CRON_INTERVAL );
                  quartzTriggerHandle = processor.createQuartzTriggerHandle( new Date(), cronInterval );

      public class StatusScheduleProcessor
          public QuartzTriggerHandle createQuartzTriggerHandle( @Expiration Date when, @IntervalCron String interval )
              MyEntity ent = new MyEntity();
              EntityManager entityManager = (EntityManager) Component.getInstance("entityManager");
              // just return null, seam will intercept and return appropriate QuartzTriggerHandle automatically.
              return null;

      Executing the code above throws:

      IllegalStateException: No active application scope 

      This is expected but my question is how do I work around this? How do I work generally done in conversation scoped context from an Application Scope?

      Thanks for the help. Sorry if anything is unclear or sounds stupid, I'm new to Seam.

        • 1. Re: Quartz, Application Scope, Injection
          Nikolay Elenkov Master

          Unclear, it is, yes :) Basically you have a chicken-egg problem. When StatusScheduleController.create is called, there is no application context active (yet), so you can't inject the StatusScheduleProcessor. Make the processor STATELESS and it should work. Btw, the safer way to do stuff only once at Seam app start up is to write an @Observer for org.jboss.seam.postInitialization.

          What do you mean by 'conversation scoped context'? I don't see anything conversation related in your code.