在富文本和文件传输到ftp服务器这里,
@Autowired视频里面是属性注入,但是目前Spring不推荐属性,那我现在用的就是设值注入。
但是在ProductManageController类中用设值注入会报一个空指针的异常,如下:java.lang.NullPointerException
com.mmall.controller.backend.ProductManageController.upload(ProductManageController.java:144)
仔细找到原因后是if(iUserService.checkAdminRole(user).isSuccess())这一语句中的iUserService空指针异常。
经过测试后,发现
原本设值注入
@Autowired
public void setIUserService (IUserService iProductService) {
this.iUserService = iUserService;
}
变为构造器注入
@Autowired
public ProductManageController(IUserService iUserService) {
this.iUserService = iUserService;
}
会解决掉这一问题,然而我在网上搜了一些资料都是说两者只是对于依赖需求的不同而有所差异,但在这里,不太理解为什么会报成空指针异常。