2013-05-17 6 views
0

@Scheduled 기능을 사용하려고합니다. thisthis 튜토리얼을 따라 왔지만 예약 된 작업을 실행할 수 없습니다.@ 스케줄 된 작업이 시작되지 않습니다.

@Component("syncWorker") 
public class SyncedEliWorker implements Worker { 
    protected Logger logger = Logger.getLogger(this.getClass()); 

    public void work() { 
     String threadName = Thread.currentThread().getName(); 
     logger.debug(" " + threadName + " has began to do scheduled scrap with id=marketwatch2"); 
    } 
} 

과 SchedulingService :

나는 노동자 만든

@Service 
public class SchedulingService { 
    protected Logger logger = Logger.getLogger(this.getClass()); 

    @Autowired 
    @Qualifier("syncWorker") 
    private Worker worker; 

    @Scheduled(fixedDelay = 5000) 
    public void doSchedule() { 
     logger.debug("Start schedule"); 

     worker.work(); 
     logger.debug("End schedule"); 
    } 
} 

을 그리고 내 애플리케이션 컨텍스트에 다른 배선을 시도했다. 서버가 오류 밖으로 시작

<beans xmlns=... 
     xmlns:task="http://www.springframework.org/schema/task" 
     ... 
     xsi:schemaLocation=" .. 
          http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd"> 

    <context:annotation-config/> 

    <task:annotation-driven executor="taskExecutor" scheduler="taskScheduler"/> 
    <task:scheduler id="taskScheduler" pool-size="3"/> 
    <task:executor id="taskExecutor" pool-size="3"/> 

    ... Other beans... 
</beans> 

: 같은 최종 버전은 보인다.

내가 누락 된 항목이 있습니까?

답변

8

<context:annotation-config />은 bean을 감지하지 않습니다. 단지 선언 된 bean의 주석을 처리합니다. 즉, 귀하의 @Service은 실제로 콩으로 변하지 않습니다.

대신 <context:component-scan base-package="com.yourcomany" />을 사용하십시오.

1

나는 똑같은 문제에 직면했지만 그 원인은 다르다. 당신이 추가 할 때

<task:annotation-driven /> 

하여, 또한 응용 프로그램 컨텍스트에서 올바른 위치에 추가하는 것을 잊지 마세요 :

xmlns:task="http://www.springframework.org/schema/task" 

과 : 나는 다음 내 최고 프로젝트에 추가했다

http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd 
관련 문제