I was wondering if there was anyway to conditionally declare a bean in an xml configuration. The goal behind this question is that I only want to enable a quartz configured job based on some value in a system environment variable. Technically speaking, I could pass the value of the system environment var to the job and check within the job whether or not to execute it, but that would be poorly designed since the bean running the job should be completely agnostic to conditions as to when it should be run.
For instance, I would like to configure my job as follows:
However, I only want this declaration based on a sys variable. To add complexity to the equation, I need to specify the trigger bean in the quartz FactorySchedulerBean, so if the trigger bean isn't actually defined, I'm not sure what to do.
<!-- Generate TeamLeader article every night -->
<bean id="fwl.service.TrendLeaderArticleService.trigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="cronExpression" value="0 0/10 * * * ? *" />
<property name="name" value="fwl.service.TrendLeaderArticleService" />
<property name="group" value="news" />
<property name="targetObject" ref="trendLeaderArticleServiceImpl"/>
<property name="targetMethod" value="createTrendLeaderArticle"/>
<property name="concurrent" value="false" />
Perhaps the solution is to always keep this defined but only inject the trigger bean into the scheduler based on some conditional parameter. But there too, I'm not sure how to do that.
I can only assume that I'm not the first one that has encountered this type of need, but a search did not reveal any promising ideas how to accomplish something like this.
Does anyone have any suggestions?