Search code examples
javaspringscheduled-tasksschedulerscheduling

Spring Scheduled tasks: specifying time zone in XML configuration


Is it possible to achieve the time zone setting in XML configuration as done in Java with the following annotation?

@Scheduled(cron = "0 0 8,20 * * *", zone = "GMT-3")

I can't see any other attributes in XML definition, but perhaps there's a workaround for achieving the desired goal.

Sample config:

<task:scheduler id="myScheduler" pool-size="2" />
<bean class="MyClass"
    id="myBean" />
<task:scheduled-tasks scheduler="myScheduler">
    <task:scheduled ref="myBean" method="gprs" fixed-rate="300000" />
    <task:scheduled ref="myBean" method="reporteGpsGprs" cron="0 0 8,20 * * *" />
</task:scheduled-tasks>

Current Spring Dependencies:

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>4.2.2.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>4.2.2.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context-support</artifactId>
        <version>4.2.2.RELEASE</version>
    </dependency>

Solution

  • Unfortuanately, looking at the xsd I don't see any other property to define timezone in xml. What you could do is use the ref and method properties to define a factory class that returns the schedule.

    Ref : http://www.springframework.org/schema/task/spring-task-4.0.xsd