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

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

Closed
spring-issuemaster opened this Issue May 21, 2018 · 0 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

spring-issuemaster 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:

  • #19319 Spring MVC and AOP: @EnableAspectJAutoProxy needs to be redeclared for each application context

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