@Resource
private ConfigService configService = new ConfigServiceImpl();
映射为空
这个mapper在Controller中是可以正常用的:
@RestController
@RequestMapping("/log")
public class LogErrorApiController {
@Resource
private LogService logService = new LogServiceImpl();
}
但是我在外部写了一个工具类,在工具类中访问,提示mapper为空:
。
public class Utils {
@Resource
private ConfigService configService = new ConfigServiceImpl();
public String lineStatFormat(List<ConfigLinesStations> linesStations){
String opList = "";
for (int i = 0; i < linesStations.size(); i++) {
List<ConfigEquipment> equipments = configService.getEquipmentList("and EquipmentId = "+
linesStations.get(i).getOPid());
System.out.println(equipments.get(0));
opList += linesStations.get(i).getOPcode()+" 【"+
equipments.get(0).getEquipmentName()+"】";
if (i < linesStations.size()){
opList += " ——>";
}
}
return opList;
}
}
运行起来就报了这么个错:
尝试过加了组件扫描,也没有用: