我有一个spring引导应用程序&如下所示
@ConfigurationProperties(prefix = “asynchronous-helper”)
public class AsynchronousHelper {
private transient ExecutorService executor;
}在我的属性文件中
asynchronous-helper.executor.maximumPoolSize=10
asynchronous-helper.executor.corePoolSize=10当maximumPoolSize工作时,corePoolSize会在以下错误中失败
Failed to bind properties under ‘asynchronous-helper.executor’ to java.util.concurrent.ExecutorService:
Property: asynchronous-helper.executor.corepoolsize
Value: 10
Origin: “asynchronous-helper.executor.corePoolSize” from property source “class path resource [backend-product.properties]”
Reason: Failed to bind properties under ‘asynchronous-helper.executor’ to java.util.concurrent.ExecutorService
Action:
Update your application’s configuration执行器的具体类是java.util.concurrent.ThreadPoolExecutor。
知道为什么会发生这种情况吗?如何解决?
发布于 2020-02-24 14:16:22
这个成功了。创建配置bean
@Configuration
public class AsyncHelperConfig {
@Value("${asynchronous-helper.executor.core-pool-size:10}")
private Integer corePoolSize;
@Value("${asynchronous-helper.executor.maximum-pool-size:10}")
private Integer maximumPoolSize;
@Value("${asynchronous-helper.executor.keep-alive-time:10}")
private Integer keepAliveTime;
private transient ExecutorService executor;
@Bean
public AsynchronousHelper asynchronousHelper(){
AsynchronousHelper asynchronousHelper = new AsynchronousHelper();
executor = new ThreadPoolExecutor(corePoolSize, maximumPoolSize,
keepAliveTime, TimeUnit.MINUTES,
new LinkedBlockingQueue<Runnable>());
asynchronousHelper.setExecutor(executor);
return asynchronousHelper;
}在beans.xml中添加了下面的配置
<bean id="AsyncHelperConfig"
class="asynchonous.AsyncHelperConfig"/>https://stackoverflow.com/questions/60349311
复制相似问题