Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-16852

Spring MVC: @EnableScheduling needs to be redeclared for each application context

    Details

    • Type: Task
    • Status: Closed
    • Priority: Minor
    • Resolution: Complete
    • Affects Version/s: 4.3.17, 5.0.5
    • Fix Version/s: 4.3.18, 5.0.7, 5.1 RC1
    • Component/s: Core
    • Labels:
      None
    • Last commented by a User:
      true

      Description

      The following is not critical, but

      I have:

      @Configuration
      @EnableScheduling
      public class SchedulingConfig implements SchedulingConfigurer {
      
      	private static final Logger logger = LoggerFactory.getLogger(SchedulingConfig.class.getSimpleName());
      
      	@Override
      	public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
      		taskRegistrar.setScheduler(taskScheduler());
      	}
      
      	@Bean(destroyMethod="shutdown")
          public TaskScheduler taskScheduler() {
      		logger.info("taskScheduler method executed ...");
      		ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler();
      		threadPoolTaskScheduler.setPoolSize(4);
      		threadPoolTaskScheduler.setThreadNamePrefix("scheduler-");
      		return threadPoolTaskScheduler;
          }
      
      }
      

      When SchedulingConfig is scanned only for the RootApplicationContext (and known that the ServletApplicationContext must be able to use/access the RootApplicationContext beans) my @Components working with @Schedule in the ServletApplicationContext does not work.

      The current solution is scan SchedulingConfig from the ServletApplicationContext

      Thus seems mandatory scans twice this SchedulingConfig from the RootApplicationContext (consider a batch process where web is not involved) and ServletApplicationContext (consider Websocket, sending messages to a JMS destination, working SimpMessagingTemplate )

      It is similar than (prior when to be fixed of course):

      I am assuming this situation would be the same or reflected for a @Configuration class working with @EnableAsync

       

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                juergen.hoeller Juergen Hoeller
                Reporter:
                dr_pompeii Manuel Jordan
                Last updater:
                Stéphane Nicoll
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Days since last comment:
                  26 weeks, 1 day ago