如果我用XML定义对象并调用var xmlApplicationContext = new XmlApplicationContext()
,则会安排作业并触发。我想要完成的是通过代码执行此操作,因为属性将是动态的,下面的方法片段编译并运行但作业未安排。这可能吗?
// SpringJob.xml
<objects xmlns="http://www.springframework.net" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<object name="emailNotification" type="Spring.Scheduling.Quartz.JobDetailObject, Spring.Scheduling.Quartz">
<property name="JobType" value="Project.Agent.Jobs.EmailNotification, Project.Agent" />
</object>
<object id="simpleTrigger" type="Spring.Scheduling.Quartz.SimpleTriggerObject, Spring.Scheduling.Quartz">
<property name="jobDetail" ref="emailNotification" />
<property name="startDelay" value="1s" />
<property name="repeatInterval" value="1s" />
<property name="repeatCount" value="0" />
</object>
<object type="Spring.Scheduling.Quartz.SchedulerFactoryObject, Spring.Scheduling.Quartz">
<property name="triggers">
<list>
<ref object="simpleTrigger" />
</list>
</property>
</object>
</objects>
//方法
var jobDetailObject = new JobDetailObject
{
JobType = new EmailNotification().GetType()
};
var simpleTrigger = new SimpleTriggerObject
{
JobDetail = jobDetailObject,
StartDelay = new TimeSpan(0, 0, 0, 1),
RepeatInterval = new TimeSpan(0, 0, 0, 1),
RepeatCount = 0
};
var scheduleTrigger = new SchedulerFactoryObject();
var triggers = new Trigger[1];
triggers[0] = simpleTrigger;
scheduleTrigger.Triggers = triggers;
scheduleTrigger.Start();
答案 0 :(得分:1)
决定放弃Quartz.Net的Spring.Net框架实现,而不是直接使用Quartz.Net。