Get user that runs an asynchronous method

前端 未结 3 2054
遥遥无期
遥遥无期 2021-01-17 18:11

I\'m trying to get the user from spring context in an application spring as follows:

Authentication auth = SecurityContextHolder.getContext().getAuthenticati         


        
3条回答
  •  终归单人心
    2021-01-17 18:35

    Maybe this helps to get execute-method called (worked in my case):

    @Override
    @Bean(name = "asyncExecutor")
    public Executor getAsyncExecutor() {
    
        CustomThreadPoolTaskExecutor executor = new CustomThreadPoolTaskExecutor();
    
        executor.setMaxPoolSize(1);
        executor.setThreadGroupName("MyCustomExecutor");
        executor.setWaitForTasksToCompleteOnShutdown(true);
        executor.setBeanName("asyncExecutor");
        executor.initialize();
    
        return new DelegatingSecurityContextAsyncTaskExecutor(executor);
    }
    

提交回复
热议问题