专注于分布式,性能优化,代码之美

Java 配置全局线程池出错

错误内容:

Unsatisfied dependency expressed through field 'AAAAAAManager'; nested exception
is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'AAAAAAManagerImpl':
Unsatisfied dependency expressed through field 'globalThreadPoolExecutor'; nested exception is org.springframework.beans
.factory.NoSuchBeanDefinitionException: No qualifying bean of type
'java.util.concurrent.ThreadPoolExecutor' available: expected at least 1 bean which qualifies as autowire candidate.
Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

 

解决:

在设置全局线程池中,需要在类开始位置设置:@Configuration注解

 

 

 

globalThreadPoolExecutor函数需要设置 Bean注解
@Bean
ThreadPoolExecutor globalThreadPoolExecutor(){
return new ThreadPoolExecutor(corePoolSize,
maximumPoolSize,
keepAliveTime,
TimeUnit.SECONDS,
new ArrayBlockingQueue<>(blockingQueueSize),
Executors.defaultThreadFactory(),
new ThreadPoolExecutor.DiscardPolicy());
}

posted on 2021-05-06 15:09  xiaohouye  阅读(897)  评论(0编辑  收藏  举报

导航

今日之劳累是为了铸造明日之辉煌,不管年龄多少,都无法阻挡我对软件艺术的追求!