Skip to content

Lazily retrieve delegate beans in AsyncConfigurer and CachingConfigurer [SPR-17021] #21559

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 Jul 9, 2018 · 1 comment
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: task A general task
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Jul 9, 2018

Marcin Grzejszczak opened SPR-17021 and commented

Having such code

@Configuration
@EnableAsync
public class FrontendAsyncConfigurerSupport extends AsyncConfigurerSupport {

    @Autowired BeanFactory beanFactory;

    @Override
    public Executor getAsyncExecutor() {
        return beanFactory.getBean(ThreadPoolTaskExecutor.class);
    }

    @Override public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
        return null;
    }
    
    @Bean
    ThreadPoolTaskExecutor myTaskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(10);
        executor.setMaxPoolSize(10);
        executor.setQueueCapacity(500);
        executor.setThreadNamePrefix("AsyncExecutor-");
        executor.initialize();
        return executor;
    }
} 

The myTaskExecutor is not applicable to get wrapped via proxy. In Spring Cloud Sleuth we're doing our best so that all instrumentation gets done automatically, behind the scenes. In this case a user has to manually call Sleuth internals to wrap the ThreadPoolTaskExecutor in a tracing representation.


Affects: 5.0.7

Reference URL: spring-cloud/spring-cloud-sleuth#1022

Issue Links:

Referenced from: commits f6fdffd

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Jul 9, 2018

Juergen Hoeller commented

A related case has been reported in #21484... While there is not much we can do about that case of triggering hard references to other beans from an AsyncConfigurer class, we should be able to make your case here - Executor post-processing - possible through lazily accessing the executor as well as the exception handler. I'll see what we can do for 5.1 here.

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) type: task A general task
Projects
None yet
Development

No branches or pull requests

2 participants