Unexpected error occurred in scheduled task
时间: 2023-10-26 12:27:28 浏览: 279
PHP异常Parse error: syntax error, unexpected T_VAR错误解决方法
"Unexpected error occurred in scheduled task"表示在定时任务中发生了意外错误。
这个错误通常是由于定时任务的执行级别高于Spring的资源注入级别,导致在服务启动时自动注入的bean还没有被完全初始化而引起的。
为了解决这个问题,可以实现ApplicationContextAware接口,重写setApplicationContext方法,并在方法中使用getBean方法获取所需要的bean。这样可以在自动注入失败时,主动获取bean对象。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [@Scheduled出现Unexpected error occurred in scheduled task](https://blog.csdn.net/Travrller/article/details/129406595)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* [异常 :Unexpected error occurred in scheduled task 。 Spring Boot定时任务调度注解@Scheduled](https://blog.csdn.net/UpjQ16/article/details/129757623)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文