2

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>
gvasquez
  • 1,919
  • 5
  • 27
  • 41

2 Answers2

3

It's possible, you could use the trigger's attribute :

<task:scheduler id="myScheduler" pool-size="2" />
<bean class="MyClass" id="myBean" />
<task:scheduled-tasks scheduler="myScheduler">
    <task:scheduled ref="myBean" method="reporteGpsGprs" trigger="myTriggerId" />
</task:scheduled-tasks>

And define an org.springframework.scheduling.support.CronTrigger just like this:

<bean id="myTriggerId" class="org.springframework.scheduling.support.CronTrigger">
    <constructor-arg name="expression" value="0 0 8,20 * * *"/>
    <constructor-arg name="timeZone" value="GMT-3"/>
</bean>
1

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

James
  • 2,756
  • 17
  • 19