Skip to content

Spring MVC: @EnableScheduling needs to be redeclared for each application context [SPR-16852] #21392

Closed
@spring-projects-issues

Description

@spring-projects-issues

Manuel Jordan opened SPR-16852 and commented

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

 


Affects: 4.3.17, 5.0.5

Issue Links:

Referenced from: commits b39ce80, 5935b7a

Backported to: 4.3.18

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)status: backportedAn issue that has been backported to maintenance branchestype: taskA general task

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions