当前位置: 首页 > 知识库问答 >
问题:

没有“ThreadPoolTaskExecutor”类型的合格bean可用

顾泰平
2023-03-14

我正在使用Spring Boot 2.2.4并尝试自定义执行器

以下是相关的课程

@Configuration
@ManagedResource
public class ExecutorConfig {
    @Bean(name = "detailsScraperExecutor")
    public Executor getDetailsAsyncExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(5);
        executor.setQueueCapacity(1000000);
        executor.setThreadNamePrefix("detailsScraperExecutor-");
        executor.initialize();
        return executor;
    }
}
@Component
@Profile("!test")
public class DetailsScraper {
    private static final Logger logger = LoggerFactory.getLogger(DetailsScraper.class);

    @Autowired
    @Qualifier("detailsScraperExecutor")
    private ThreadPoolTaskExecutor detailsScraperExecutor;
}
spring.jmx.enabled=false

spring.datasource.url=jdbc:postgresql://example.com:5432/example
spring.datasource.username=example
spring.datasource.password=password

spring.jpa.open-in-view=false

logging.level.com.gargoylesoftware.htmlunit=ERROR

spring.datasource.hikari.maximumPoolSize = 30



app.properties.parseaddress.endpoint=http://example.com

共有1个答案

经兴安
2023-03-14

您需要注入与配置中声明的相同类型的类,但不需要注入更高级别的类。但你可以使用较低级别的。

 @Autowired
 private Executor detailsScraperExecutor;
 类似资料: