我想在我的数据库中插入一些数据。但我抓住了
"ERROR: org.springframework.scheduling.support.TaskUtils$LoggingErrorHandler - Unexpected error occurred in scheduled task.
java.lang.NullPointerException"
我不知道该怎么做。
public class HeadHunterImport {
@Autowired
private static HeadHunterService headHunterService;
@Scheduled(fixedRate = 600000)
public void AsyncRemovalOldData() {
headHunterService.addHeadHunter("Moscow", 100, 100) ;
}
如果我在控制器中调用它,它将正常工作。怎么了?
答案 0 :(得分:2)
if(headHunterService!=null){
headHunterService.addHeadHunter("Moscow", 100, 100) ;
}else{
Sysem.out.println("headHunterService Object is null");
}
如果headHunterService返回null,请确保您的上下文中存在以下代码。
<context:annotation-config/>
<context:component-scan base-package="your.package.name.here"/>
确保使用@Component
注释以下类 @Component
class HeadHunterService {
}
or
you need the setter injection for headHunterService