Note that there are some explanatory texts on larger screens.

plurals
  1. POproblems with ApplicationContext and Spring batch
    text
    copied!<p>i'm working with Spring batch, i've done the batch job, configured with an xml file, i also put all the Quartz configuration in that xml file, (the trigger, schedulerFactoryBean and jobDetail); this is a java project, and i'm trying to load the application context, as an stand alone in a main class; as far as the documentation says, this should make Quartz to start running and is doing it, the problem is when the job runs with the trigger and calls the service, is like all the Autowired beans hadn’t had been loaded, so is giving me an NullpointerException… this is the code that the job calls after the trigger is fired, and when the JobParametersBuilder is created is when everything crash, Quartz still running though...</p> <p>could someone helpme with this?</p> <p>//class called by the job</p> <pre class="lang-java prettyprint-override"><code>public class MainJobClass { private static Logger log = Logger.getLogger(MainJobClass.class); @Autowired private SimpleJobLauncher launcher; @Autowired private Job job; public void executeJob(){ try{ log.info("***** Staring job......"); JobParametersBuilder builder = new JobParametersBuilder(); builder.addDate("date", new Date()); builder.addString("sendEmailJob", "Send email to approvers"); JobParameters parameters = builder.toJobParameters(); launcher.run(job, parameters); }catch(Exception e){ log.error("Error on executing job"+e.fillInStackTrace()); } } public void setLauncher(SimpleJobLauncher launcher) { this.launcher = launcher; } public void setJob(Job job) { this.job = job; } </code></pre> <p>simple main method calling App context:</p> <pre class="lang-java prettyprint-override"><code> public static void main(String[] args){ ApplicationContext context = new ClassPathXmlApplicationContext("/com/ge/grt/email/grt_email_send.xml"); } </code></pre> <p>error line: </p> <pre><code>INFO [DefaultQuartzScheduler_Worker-1] (MainJobClass.java:29) - ***** Staring job...... ERROR [DefaultQuartzScheduler_Worker-1] (MainJobClass.java:40) - Error on executing jobjava.lang.NullPointerException </code></pre> <p>this are the Quartz beans on the xml file:</p> <pre class="lang-xml prettyprint-override"><code>&lt;!-- Scheudler Factory bean, the job will run when the context is loaded --&gt; &lt;bean id="schedulerFactoryBean" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"&gt; &lt;property name="triggers"&gt; &lt;list&gt; &lt;ref bean="beanTrigger"&gt;&lt;/ref&gt; &lt;/list&gt; &lt;/property&gt; &lt;/bean&gt; &lt;!-- definition of the trigger --&gt; &lt;!-- defining the execution date: (once every week on monday at 8:00 AM) --&gt; &lt;bean id="beanTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean"&gt; &lt;property name="jobDetail" ref="jobDetail" /&gt; &lt;property name="misfireInstructionName" value="MISFIRE_INSTRUCTION_FIRE_ONCE_NOW"/&gt; &lt;!-- &lt;property name="cronExpression" value="0 0 8 ? * MON" /&gt; --&gt; &lt;property name="cronExpression" value="0 0/1 * * * ?" /&gt; &lt;/bean&gt; &lt;!-- definiton of job detail bean --&gt; &lt;bean id="jobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"&gt; &lt;property name="targetObject" ref="mainJobClass" /&gt; &lt;property name="targetMethod" value="executeJob" /&gt; &lt;property name="concurrent" value="false"&gt;&lt;/property&gt; &lt;/bean&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload