msaleh
Jun 4th, 2012, 09:58 AM
i have a TimerTask class used to run scheduled jobs and when the job runs it executes some transactions on the database so i have a Dao as follows:
@Repository
@Transactional
public class CampaignDaoImpl extends BasicDao implements CampaignDao {
@Override
public Campaign getCampaignListById(long id)
throws DataAccessLayerException {
return (Campaign) super.getById(Campaign.class, id);
}
}
and the TimerTask:
@Service("campaignSchedule")
public class CampaignSchedule extends TimerTask {
@Autowired
private CampaignDao campaignDao;
public synchronized void schedule() throws DException {
log.debug("schedule >>> CampaignSchedule");
Campaign cam= campaignDao.getCampaignListById(1);
}
}
the annotation scanner is set correctly, and the autowiring works fine in other classes in same package
<context:component-scan base-package="com.mypackage" />
when debugging i found that campaignDao is null.
please advise how to fix this error.
@Repository
@Transactional
public class CampaignDaoImpl extends BasicDao implements CampaignDao {
@Override
public Campaign getCampaignListById(long id)
throws DataAccessLayerException {
return (Campaign) super.getById(Campaign.class, id);
}
}
and the TimerTask:
@Service("campaignSchedule")
public class CampaignSchedule extends TimerTask {
@Autowired
private CampaignDao campaignDao;
public synchronized void schedule() throws DException {
log.debug("schedule >>> CampaignSchedule");
Campaign cam= campaignDao.getCampaignListById(1);
}
}
the annotation scanner is set correctly, and the autowiring works fine in other classes in same package
<context:component-scan base-package="com.mypackage" />
when debugging i found that campaignDao is null.
please advise how to fix this error.