定时任务类中的@Autowired无法注入成功
YABAJ 2017-10-26 12:35:08 大家帮帮忙看看是为什么要怎么改....非常感谢......
在weblogic上部署项目报错:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'erpOracleController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.herysoft.expertsys.erp.dao.MaterialDicDao org.herysoft.expertsys.erp.controller.ErpOracleController.materialDicDao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.herysoft.expertsys.erp.dao.MaterialDicDao] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
经排查,问题就在定时任务所在的controller里的@Autowired无法注入成功
而项目部署在tomcat下就是可以绑定成功的,不会报错,一到weblogic就报错了。
在下面定时任务配置中调用到了该controller,在前面的配置文件中也有配component-scan的
<task:scheduled-tasks scheduler="myScheduler">
<task:scheduled ref="erpOracleController" method="impMaterial" cron="0 0 01 * * ?"/>
</task:scheduled-tasks>
定时任务类:
@Controller("erpOracleController")
@RequestMapping(value = "/basic/rep")
public class ErpOracleController {
@Autowired
private MaterialDicDao materialDicDao;
@Autowired
private MaterialDao materialDao;
@Autowired
private DicUtil dicUtil;
@Autowired
private DictionaryDao dictionaryDao;
public void impMaterial(){
........
}
......
}