Spring Boot+mybatis-plus新人不踩坑
搞了一下午
1.SpringBoot自动注入后空指针
2.使用@Autowired出现Could not autowire. No beans of ‘Mapperuser’ type found.
3.使用mybatis-plus时遇到Failed to load ApplicationContext
4.测试类中遇到Unable to find a @SpringBootConfiguration的情况
5.依赖整合(可直接复制使用)
1.SpringBoot自动注入后空指针
加入@RunWith(SpringRunner.class)
即可
2.使用@Autowired出现Could not autowire. No beans of ‘Mapperuser’ type found.
把@Autowired换成@Resource就好了
3.使用mybatis-plus时遇到Failed to load ApplicationContext
问题原因在于配置mybatis规则与resources包的mapper冲突
可将resources/mapper删除即可正常运行
(可将sql连接池放在properties里)
4.测试类中遇到Unable to find a @SpringBootConfiguration的情况
依据提示,将@SpringBootTest更改为@SpringBootTest(classes = main方法名.class)
5.依赖整合
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>cn.year9</groupId