Mybatis的mapper使用springbootTest报错Find why ‘xxxMapper‘ could be null

Posted 加辣椒了吗?

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Mybatis的mapper使用springbootTest报错Find why ‘xxxMapper‘ could be null相关的知识,希望对你有一定的参考价值。

报错:Find why userMapper‘ could be null

在测试类调试报错:

报错信息:

java.lang.NullPointerException at
com.sutao.gdc.GdcApplicationTests.ee(GdcApplicationTests.java:146) 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.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:725)
at
org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
at
org.junit.jupiter.engine.execution.InvocationInterceptorChain V a l i d a t i n g I n v o c a t i o n . p r o c e e d ( I n v o c a t i o n I n t e r c e p t o r C h a i n . j a v a : 131 ) a t o r g . j u n i t . j u p i t e r . e n g i n e . e x t e n s i o n . T i m e o u t E x t e n s i o n . i n t e r c e p t ( T i m e o u t E x t e n s i o n . j a v a : 149 ) a t o r g . j u n i t . j u p i t e r . e n g i n e . e x t e n s i o n . T i m e o u t E x t e n s i o n . i n t e r c e p t T e s t a b l e M e t h o d ( T i m e o u t E x t e n s i o n . j a v a : 140 ) a t o r g . j u n i t . j u p i t e r . e n g i n e . e x t e n s i o n . T i m e o u t E x t e n s i o n . i n t e r c e p t T e s t M e t h o d ( T i m e o u t E x t e n s i o n . j a v a : 84 ) a t o r g . j u n i t . j u p i t e r . e n g i n e . e x e c u t i o n . E x e c u t a b l e I n v o k e r ValidatingInvocation.proceed(InvocationInterceptorChain.java:131) at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:149) at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:140) at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:84) at org.junit.jupiter.engine.execution.ExecutableInvoker ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)atorg.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:149)atorg.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:140)atorg.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:84)atorg.junit.jupiter.engine.execution.ExecutableInvokerReflectiveInterceptorCall.lambda$ofVoidMethod 0 ( E x e c u t a b l e I n v o k e r . j a v a : 115 ) a t o r g . j u n i t . j u p i t e r . e n g i n e . e x e c u t i o n . E x e c u t a b l e I n v o k e r . l a m b d a 0(ExecutableInvoker.java:115) at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda 0(ExecutableInvoker.java:115)atorg.junit.jupiter.engine.execution.ExecutableInvoker.lambdainvoke 0 ( E x e c u t a b l e I n v o k e r . j a v a : 105 ) a t o r g . j u n i t . j u p i t e r . e n g i n e . e x e c u t i o n . I n v o c a t i o n I n t e r c e p t o r C h a i n 0(ExecutableInvoker.java:105) at org.junit.jupiter.engine.execution.InvocationInterceptorChain 0(ExecutableInvoker.java:105)atorg.junit.jupiter.engine.execution.InvocationInterceptorChainInterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
at
org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
at
org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
at
org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
at
org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104)
at
org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98)
at
org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod 7 ( T e s t M e t h o d T e s t D e s c r i p t o r . j a v a : 214 ) a t o r g . j u n i t . p l a t f o r m . e n g i n e . s u p p o r t . h i e r a r c h i c a l . T h r o w a b l e C o l l e c t o r . e x e c u t e ( T h r o w a b l e C o l l e c t o r . j a v a : 73 ) a t o r g . j u n i t . j u p i t e r . e n g i n e . d e s c r i p t o r . T e s t M e t h o d T e s t D e s c r i p t o r . i n v o k e T e s t M e t h o d ( T e s t M e t h o d T e s t D e s c r i p t o r . j a v a : 210 ) a t o r g . j u n i t . j u p i t e r . e n g i n e . d e s c r i p t o r . T e s t M e t h o d T e s t D e s c r i p t o r . e x e c u t e ( T e s t M e t h o d T e s t D e s c r i p t o r . j a v a : 135 ) a t o r g . j u n i t . j u p i t e r . e n g i n e . d e s c r i p t o r . T e s t M e t h o d T e s t D e s c r i p t o r . e x e c u t e ( T e s t M e t h o d T e s t D e s c r i p t o r . j a v a : 66 ) a t o r g . j u n i t . p l a t f o r m . e n g i n e . s u p p o r t . h i e r a r c h i c a l . N o d e T e s t T a s k . l a m b d a 7(TestMethodTestDescriptor.java:214) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:210) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:135) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:66) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda 7(TestMethodTestDescriptor.java:214)atorg.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)atorg.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTe

以上是关于Mybatis的mapper使用springbootTest报错Find why ‘xxxMapper‘ could be null的主要内容,如果未能解决你的问题,请参考以下文章

Mybatis通用Mapper

spring boot集成MyBatis 通用Mapper 使用总结

mapper.xml的使用

mybatis使用通用mapper步骤

MyBatis动态Sql 的使用

MyBatis 中 Mapper 接口的使用原理