您的当前位置:首页正文

expected to be of type ‘org.springframework.scheduling.TaskScheduler‘ but was actually of NullBean

2024-11-29 来源:个人技术集锦

springboot在整合websocket出现一下报错:

org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'defaultSockJsTaskScheduler' is expected to be of type 'org.springframework.scheduling.TaskScheduler' but was actually of type 'org.springframework.beans.factory.support.NullBean'

解决方案

添加一个定时任务的配置类来创建一个ThreadPoolTaskScheduler对象。

 
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
 
/**
 * @author 寅灯
 * @version 3.0
 */
@Configuration
public class ScheduledConfig {
    @Bean
    public TaskScheduler taskScheduler() {
        ThreadPoolTaskScheduler scheduling = new ThreadPoolTaskScheduler();
        scheduling.setPoolSize(20);
        scheduling.initialize();
        return scheduling;
    }
 
}
显示全文