转载自:https://jiming.blog.csdn.net/article/details/103185972
根据博主的分析,可能是controller
层没有加@autowired
进行了分析。
发现是因为自己在controller
层中对xxImpl
实现类的通过new
进行了实例化。
通过new
实例化的对象,和@Autowired
的对象,是两个不同的对象,如果用new
出的对象去调用某方法,而恰巧某方法中调用了spring
托管的对象,那肯定会报错。
举例:
controller层:
通过new
来实例化对象employee
,employee
调用getEmployees()
方法。
service层
getEmployees()
方法中引用了employeeMapper
,所以对于controller
层中new
出来的对象,是识别不了的,因此,会报错。