2013-08-28 5 views
0

DB에 데이터를 일부 삽입하려고합니다. 하지만 내가 잡는다예약 된 메서드에서 NullPointer 예외가 발생했습니다.

"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) ; 

    } 

컨트롤러로 호출하면 문제가 없습니다. 뭐가 문제 야?

답변

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 
+0

이 honset되기 위하여, 그렇지 않은 진짜 대답은하지만'(headHunterService! = NULL)이'한 경우 나 삭제하는 생각입니다'static'에 있는지 다음과 같은 클래스의 주석을 확인 성명서. 그래서 내가 너를 선택할거야. – Tony

관련 문제