Atul
Atul

Reputation: 3357

Spring Boot 2.6.6 Failed to create asynch executor instance : Failed to instantiate [java.util.concurrent.Executor]: Illegal arguments

I am upgrading Spring Boot version from 2.4.6 to 2.6.6

After upgrade, one of the class failed to load and giving an error like below:

Failed to instantiate [java.util.concurrent.Executor]: Illegal arguments to factory method 'threadPoolTaskExecutor'; args: ; nested exception is java.lang.IllegalArgumentException: object is not an instance of declaring class

It failed to create a instance of executor service class.

This is the code:

@Configuration
@EnableAsync
public class ApplicationAsynchConfig  implements AsyncConfigurer{
    
    @Bean(name = "threadPoolTaskExecutor")
    public Executor threadPoolTaskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        //set some properties
        return executor;
    }
  }

Any idea what is going wrong with the new Spring Boot version for this?

Upvotes: 1

Views: 4226

Answers (1)

Atul
Atul

Reputation: 3357

I am not sure about the approach to solve the issue but after the changes the application started and working as expected.

The solution is to remove the AsyncConfigurer

Here is the code:

@Configuration
@EnableAsync
public class ApplicationAsynchConfig {
    
    @Bean(name = "threadPoolTaskExecutor")
    public Executor threadPoolTaskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        //set some properties
        return executor;
    }
  }

Upvotes: 2

Related Questions