有个特殊需求,一个普通的类,定时任务,需要获取SpringMVC的controller对应的bean:

方法:

WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext();
FluController fluController = (FluController) wac.getBean("fluController");
if(fluController == null){
logger.error(" fluControler is null !!!!!!");
return;
}

如果报错,找不到bean fluController,那么就把这个controller配置到 applicationContext.xml中即可。

05-04 12:22