Spring.Net 编程与 XML 配置

发布于 2024-10-28 03:31:05 字数 2131 浏览 5 评论 0原文

如果我在 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();

If I define the objects in XML and call var xmlApplicationContext = new XmlApplicationContext() the job is scheduled and fires. What I would like to accomplish is to do this through code as the properties will be dynamic, the method fragment below compiles and runs but the job is not scheduled. Is this possible?

// 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>

// Method

 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();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

≈。彩虹 2024-11-04 03:31:05

决定放弃 Quartz.Net 的 Spring.Net 框架实现,而是直接使用 Quartz.Net。

Decided to abandon the Spring.Net framework implementation of Quartz.Net instead I am using Quartz.Net directly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文