diff --git a/spring-context/src/main/java/org/springframework/scheduling/annotation/EnableScheduling.java b/spring-context/src/main/java/org/springframework/scheduling/annotation/EnableScheduling.java index 35e2891f311..72a884a6b0e 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/annotation/EnableScheduling.java +++ b/spring-context/src/main/java/org/springframework/scheduling/annotation/EnableScheduling.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,16 +37,18 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar; * @Configuration * @EnableScheduling * public class AppConfig { + * * // various @Bean definitions * } * * This enables detection of @{@link Scheduled} annotations on any Spring-managed - * bean in the container. For example, given a class {@code MyTask} + * bean in the container. For example, given a class {@code MyTask} * *
  * package com.myco.tasks;
  *
  * public class MyTask {
+ *
  *     @Scheduled(fixedRate=1000)
  *     public void work() {
  *         // task execution logic
@@ -60,6 +62,7 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar;
  * @Configuration
  * @EnableScheduling
  * public class AppConfig {
+ *
  *     @Bean
  *     public MyTask task() {
  *         return new MyTask();
@@ -72,6 +75,7 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar;
  *
  * 
  * @Configuration
+ * @EnableScheduling
  * @ComponentScan(basePackages="com.myco.tasks")
  * public class AppConfig {
  * }
@@ -83,6 +87,7 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar; * @Configuration * @EnableScheduling * public class AppConfig { + * * @Scheduled(fixedRate=1000) * public void work() { * // task execution logic @@ -100,6 +105,7 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar; * @Configuration * @EnableScheduling * public class AppConfig implements SchedulingConfigurer { + * * @Override * public void configureTasks(ScheduledTaskRegistrar taskRegistrar) { * taskRegistrar.setScheduler(taskExecutor()); @@ -111,11 +117,11 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar; * } * }
* - * Note in the example above the use of {@code @Bean(destroyMethod="shutdown")}. This - * ensures that the task executor is properly shut down when the Spring application - * context itself is closed. + *

Note in the example above the use of {@code @Bean(destroyMethod="shutdown")}. + * This ensures that the task executor is properly shut down when the Spring + * application context itself is closed. * - * Implementing {@code SchedulingConfigurer} also allows for fine-grained + *

Implementing {@code SchedulingConfigurer} also allows for fine-grained * control over task registration via the {@code ScheduledTaskRegistrar}. * For example, the following configures the execution of a particular bean * method per a custom {@code Trigger} implementation: @@ -124,6 +130,7 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar; * @Configuration * @EnableScheduling * public class AppConfig implements SchedulingConfigurer { + * * @Override * public void configureTasks(ScheduledTaskRegistrar taskRegistrar) { * taskRegistrar.setScheduler(taskScheduler()); @@ -150,22 +157,32 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar; * *

For reference, the example above can be compared to the following Spring XML * configuration: + * *

  * {@code
  * 
+ *
  *     
+ *
  *     
- *     
+ *
+ *     
+ *         
+ *     
+ *
  *     
+ *
  * 
  * }
- * the examples are equivalent save that in XML a fixed-rate period is used + * + * The examples are equivalent save that in XML a fixed-rate period is used * instead of a custom {@code Trigger} implementation; this is because the * {@code task:} namespace {@code scheduled} cannot easily expose such support. This is * but one demonstration how the code-based approach allows for maximum configurability * through direct access to actual componentry.

* * @author Chris Beams + * @author Juergen Hoeller * @since 3.1 * @see Scheduled * @see SchedulingConfiguration