Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spring-projects-issues opened this issue May 21, 2018 · 0 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: backported An issue that has been backported to maintenance branches type: task A general task
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented May 21, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: backported An issue that has been backported to maintenance branches type: task A general task
Projects
None yet
Development

No branches or pull requests

2 participants