为了账号安全,请及时绑定邮箱和手机立即绑定

SSM中,Method的invoke方法调用基于注解的Service有空指针异常 ?

SSM中,Method的invoke方法调用基于注解的Service有空指针异常 ?

御羽倾城 2017-09-24 11:23:52
@Component @RequestMapping("/student") public class StudentController extends BaseController { @Autowired StudentService studentService; @RequestMapping(value = "/listStudent") public void list() throws Exception { ... //这里调用getStudents方法正常 List<Student> stuList = this.getStudents(); ... } public List<Student> getStudents() { try { List<Student> stuList = studentService.listStudent(page, rows, sort, order); return stuList; } catch (Exception e) { e.printStackTrace(); } return null; } @RequestMapping(value = "/export") public void export() throws Exception { ... // 获取类 //根据传过来的参数 className, methodName 调用相应的方法 Class clazz = Class.forName(className); Object o = clazz.newInstance(); Method m = clazz.getDeclaredMethod(methodName); //这里调用getStudents方法出现studentService空指针异常 List list = (List) m.invoke(o); ... } }以上是省略过的代码!
查看完整描述

3 回答

?
灬java

TA贡献3条经验 获得超0个赞

//img1.sycdn.imooc.com//59c86219000132e602910194.jpg 这里返回空


查看完整回答
反对 回复 2017-09-25
?
慕的地7538294

TA贡献12条经验 获得超2个赞

不知道你用反射的意图,既然已经注入service。
按照错误提示,调试一下吧,找到空指针的地方。

查看完整回答
反对 回复 2017-09-24
?
慕的地7538294

TA贡献12条经验 获得超2个赞

也就是说你的m是null

查看完整回答
反对 回复 2017-09-24
  • 3 回答
  • 0 关注
  • 4436 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信