java.lang.NullPointerException
at com.example.new_oa.identity.service.impl.IdentityServiceImpl.getAllDepts(IdentityServiceImpl.java:51)
at com.example.new_oa.NewOaApplicationTests.initDb(NewOaApplicationTests.java:31)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:74)
at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:84)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
笔者在进行开发测试的时候,代码中是通过注解将业务层对象放入spring容器的,而在测试时,时通过手动new的业务层对象,去调用的方法,但是在方法的内部却出现了空指针的情况,这是怎么回事呢?后来发现,在我的业务层方法中,是依赖了持久层对象的,而持久层对象又是通过注解引入的,前面由于业务层对象是通过手动new出来的,所以该对象中并没有把持久层对象注入进去,所以出现了空指针的情况。所以将手动的new的对象,修改为从容器中获取就好了。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。