Change spring bean properties during setup
In the spring servlet xml file I use org.springframework.scheduling.quartz.SchedulerFactoryBean
to run a set of triggers regularly.
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref local="AwesomeTrigger" />
<ref local="GreatTrigger" />
<ref local="FantasticTrigger"/>
</list>
</property>
</bean>
The problem is that in different environments I don't want to fire some triggers. Is there a way to include some kind of config or variable defined either in my build.properties for the environment or in the custom spring custom properties file that helps the xml bean determine which triggers should be included in the list? So, for example, AwesomeTrigger
will be called in development, but not qa.
a source to share
Create a factory bean that returns a list of triggers based on a property
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<bean class="com.yourcompany.FactoryBeanThatReturnsAListOfTriggers">
<property name="triggerNames" value="${some.property}" />
</bean>
</property>
</bean>
<context:property-placeholder location="classpath:your.properties" />
Reference:
a source to share
I had the same problem.
What I've done:
I disabled the trigger bean to add the property.
And after I overridden SchedulerFactoryBean.setTriggers and I only set triggers activated.
You just need to use these new beans in your xml files and included in your properties file.
Example:
public void setTriggers(Trigger[] triggers) {
ArrayList<Trigger> triggersToSchedule = new ArrayList<Trigger>();
for(Trigger trigger : triggers){
if(trigger instanceof SimpleTriggerBeanEnabler){
if(((SimpleTriggerBeanEnabler)(trigger)).isEnabled()){
triggersToSchedule.add(trigger);
}
}
else{
triggersToSchedule.add(trigger);
}
}
super.setTriggers(triggersToSchedule.toArray(new Trigger[triggersToSchedule.size()]));
}
a source to share