Note that there are some explanatory texts on larger screens.

plurals
  1. POorg.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [org.quartz.JobDetail] is defined
    text
    copied!<p>I get the following exception when running my Spring application:</p> <pre><code>org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [org.quartz.JobDetail] is defined: expected single matching bean but found 2: [quartzSchedulerRuntime, jobDetail] </code></pre> <p>This is part where I configure quartz in <code>root-context.xml</code>.</p> <p><strong>root-context.xml</strong></p> <pre><code>&lt;bean name="quartzSchedulerRuntime" class="org.springframework.scheduling.quartz.JobDetailBean"&gt; &lt;property name="jobClass" value="com.task.QuartzScheduler" /&gt; &lt;property name="jobDataAsMap"&gt; &lt;map&gt; &lt;entry key="runtimeReportServiceImpl" value-ref="RuntimeReportService" /&gt; &lt;/map&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="cronTriggerRuntime" class="org.springframework.scheduling.quartz.CronTriggerBean"&gt; &lt;property name="jobDetail" ref="quartzSchedulerRuntime" /&gt; &lt;property name="cronExpression" value="0 30 12 ? * MON *" /&gt; &lt;/bean&gt; &lt;bean id="quartzScheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean" lazy-init="false"&gt; &lt;property name="schedulerContextAsMap"&gt; &lt;map&gt; &lt;entry key="reportSchedulerServiceImpl" value-ref="reportSchedulerServiceImpl"&gt;&lt;/entry&gt; &lt;/map&gt; &lt;/property&gt; &lt;property name="jobDetails"&gt; &lt;list&gt; &lt;ref bean="quartzSchedulerRuntime" /&gt; &lt;ref bean="jobDetail"/&gt; &lt;/list&gt; &lt;/property&gt; &lt;property name="triggers"&gt; &lt;list&gt; &lt;ref bean="cronTriggerRuntime" /&gt; &lt;ref bean="jobTrigger"/&gt; &lt;/list&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="jobDetailFactory" class="org.springframework.beans.factory.config.ObjectFactoryCreatingFactoryBean"&gt; &lt;property name="targetBeanName"&gt; &lt;idref local="jobDetail" /&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="jobDetail" class="org.springframework.scheduling.quartz.JobDetailBean" scope="prototype"&gt; &lt;property name="jobClass" value="com.scheduler.SMTPMailJob " /&gt; &lt;property name="jobDataAsMap"&gt; &lt;map&gt; &lt;entry key="reportSchedulerServiceImpl" value-ref="reportSchedulerServiceImpl" /&gt; &lt;entry key="filterUtil" value-ref="filterUtil" /&gt; &lt;entry key="reportService" value-ref="reportService" /&gt; &lt;entry key="fusionChartHtmlToImage" value-ref="fusionChartHtmlToImage"/&gt; &lt;entry key="fcproperties" value-ref="fcproperties"/&gt; &lt;/map&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="jobTriggerFactory" class="org.springframework.beans.factory.config.ObjectFactoryCreatingFactoryBean"&gt; &lt;property name="targetBeanName"&gt; &lt;idref local="jobTrigger" /&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="jobTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean" scope="prototype"&gt; &lt;property name="jobDetail" ref="jobDetail" /&gt; &lt;property name="cronExpression" value="0 0 9 1/1 * ? *" /&gt; &lt;/bean&gt; </code></pre> <p><strong>EDIT:</strong> I have narrowed down the problem to this. I have created a class called RScheduler that is supposed to schedule the jobs. In that class I have declared:</p> <pre><code>Scheduler scheduler; ObjectFactory&lt;JobDetail&gt; jobDetailFactory; ObjectFactory&lt;CronTrigger&gt; jobTriggerFactory; @Autowired public ReportScheduler(Scheduler scheduler,ObjectFactory&lt;JobDetail&gt; jobDetailFactory,ObjectFactory&lt;CronTrigger&gt; jobTriggerFactory) throws SchedulerException { Assert.notNull(scheduler, "scheduler cannot be null"); Assert.notNull(jobDetailFactory, "jobDetailFactory cannot be null"); Assert.notNull(jobTriggerFactory, "jobTriggerFactory cannot be null"); this.scheduler = scheduler; this.jobDetailFactory=jobDetailFactory; this.jobTriggerFactory=jobTriggerFactory; this.scheduler.getContext().put("reportSchedulerServ", reportSchedulerServ); } </code></pre> <p>I am calling the job in another method like:</p> <pre><code>JobDetail jobDetail = jobDetailFactory.getObject(); </code></pre> <p>This is the line giving me the error.</p> <p><strong>EDIT 2:</strong> I am guessing the problem is that I require many jobs to be triggered. So i have created the </p> <p><code>ObjectFactory&lt;JobDetail&gt; jobDetailFactory</code> </p> <p>to capture objects via the <code>jobDetailFactory</code> bean. I think , the line </p> <p><code>JobDetail jobDetail = jobDetailFactory.getObject()</code> </p> <p>isn't able to figure out which JobDetail bean to get, since it has two job details. I don't understand how the <code>@Qualifier</code> notation will help in determining that. Any particular way in which I can resolve this error..? </p>
 

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