Question:
Because the project uses microservices, a service is created in the microservices to write mybatis plus in order to save trouble. However, a null pointer error occurs when JUnit tests after writing according to the official website documents.
Test class of official website document:
An error occurred:
The value of usermapper was found to be empty
By checking the data, it is found that this is because ordinary classes can’t use springbeans, so ordinary test classes can’t get beans, so they report null pointers. Therefore, we need to make the test class get the bean.
Solution:
Add test dependency:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
And add notes on the test class:
@SpringBootTest
@RunWith(SpringJUnit4ClassRunner.class)
solve the problem
Read More:
- [Solved] mybatis plus Insert Error: mybatis plus Error setting null for parameter #1 with JdbcType OTHER
- Dubbo failed to register and consumer null pointer exception
- mybatis Error: All elements are null [How to Solve]
- Mybatis Error: All elements are null [How to Solve]
- JUnit test classes error: java.lang.IllegalStateException: Failed to load ApplicationContext
- [Solved] Mybatis.generator error: Failed to execute goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.2
- How to Solve JUnit Debugging initializationerror ERROR
- [Solved] Tk-Mybatis Error: tk.mybatis.mapper.MapperException:
- Dubbo Frame Write Junit Error: ERROR org.springframework.test.context.Testcontextmanager
- How to Solve Junit Unit Test Error: “No runnable methods“
- mybatis-plus Common Error and Their Solution
- [Solved] Mybatis Error: Could not find resource mybatis-conf.xml
- Mapper.xml Error: Error setting non null for parameter #3 with JdbcType null.
- [Solved] Openfegn Remote Call Error: java.lang.NullPointerException: null
- [Solved] Mybatis add dependencies Error: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration.
- Mybatisenumtypehandler upgrade error of mybatis plus
- springboot Integrate mybatis Error: Error creating bean with name ‘deptController‘: Unsatisfied dependency expresse
- [Solved] Mybatis Batch Modify Error: multi-statement not allow
- serviceimpl inherits generic public impl startup error: ClassCastException (Mybatis-plus version Issue)
- Mybatis single parameter pass in exception (How to Fix)