package <%=packageName%>.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.bind.RelaxedPropertyResolver;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;

@Configuration
@EnableAsync
@EnableScheduling
public class AsyncConfiguration implements AsyncConfigurer, EnvironmentAware {

    private final Logger log = LoggerFactory.getLogger(AsyncConfiguration.class);

    private RelaxedPropertyResolver propertyResolver;

    @Override
    public void setEnvironment(Environment environment) {
        this.propertyResolver = new RelaxedPropertyResolver(environment, "async.");
    }

    @Override
    public Executor getAsyncExecutor() {
        log.debug("Creating Async Task Executor");
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(propertyResolver.getProperty("corePoolSize", Integer.class, 2));
        executor.setMaxPoolSize(propertyResolver.getProperty("corePoolSize", Integer.class, 50));
        executor.setQueueCapacity(propertyResolver.getProperty("corePoolSize", Integer.class, 10000));
        executor.setThreadNamePrefix("<%= _.slugify(baseName) %>-Executor-");
        executor.initialize();
        return executor;
    }
}

@@ -199,16 +199,68 @@
 tAware;%0A
+import org.springframework.context.annotation.Bean;%0A
 import o
@@ -1102,32 +1102,42 @@
 %0A%0A    @Override%0A
+    @Bean%0A
     public Execu
@@ -1665,39 +1665,8 @@
 %22);%0A
-        executor.initialize();%0A
     

Use @Bean for AsyncExecutor