mybatisplus开始学习时,常出现的错误

按照mybatisplus官网的快速开始,步骤内容没有错误。但是运行测试报错,遇到两个错误,这是第一个错误:
java.lang.NullPointerException: Cannot invoke "com.nhc.mybatis.mapper.UserMapper.selectList(com.baomidou.mybatisplus.core.conditions.Wrapper)" because "this.userMapper" is null

	at com.nhc.mybatis.test.TestUser.insert(TestUser.java:31)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
	at java.base/java.lang.reflect.Method.invoke(Method.java:577)
	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.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)

几经查找,在测试类上加上这两个注解就好了

@SpringBootTest @RunWith(SpringRunner.class)

还有一个常见错误,错误如下:

============================
CONDITIONS EVALUATION REPORT
============================


Positive matches:
-----------------

   AopAutoConfiguration matched:
      - @ConditionalOnProperty (spring.aop.auto=true) matched (OnPropertyCondition)

   AopAutoConfiguration.ClassProxyingConfiguration matched:
      - @ConditionalOnMissingClass did not find unwanted class 'org.aspectj.weaver.Advice' (OnClassCondition)
      - @ConditionalOnProperty (spring.aop.proxy-target-class=true) matched (OnPropertyCondition)

   DataSourceAutoConfiguration matched:
      - @ConditionalOnClass found required classes 'javax.sql.DataSource', 'org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType' (OnClassCondition)
      - @ConditionalOnMissingBean (types: io.r2dbc.spi.ConnectionFactory; SearchStrategy: all) did not find any beans (OnBeanCondition)

   DataSourceAutoConfiguration.PooledDataSourceConfiguration matched:
      - AnyNestedCondition 1 matched 1 did not; NestedCondition on DataS
  • 4
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
当我们在使用MyBatis Plus,在启动过程中可能会遇到一些错误。以下是一些见的错误和可能的解决方案: 1. 错误信息:"No qualifying bean of type 'xxx' available"(找不到类型为'xxx'的合格Bean) 解决方案:这通是由于没有正确地配置相关的Bean导致的。你需要确保在你的配置文件或注解中正确地声明了这个Bean。 2. 错误信息:"Invalid bound statement (not found)"(无效的绑定语句(未找到)) 解决方案:这通是由于没有正确地配置MyBatis的映射文件导致的。你需要确保你的映射文件中正确地定义了对应的SQL语句,以便MyBatis能够找到。 3. 错误信息:"Error: The mapper's package must be specified"(错误:必须指定映射器的包名) 解决方案:这是由于没有配置正确的Mapper扫描路径导致的。你需要在你的配置文件中明确指定Mapper接口所在的包名,以便MyBatis Plus能够找到和加载它们。 4. 错误信息:"Error creating bean with name 'sqlSessionFactory'"(创建'sqlSessionFactory' Bean发生错误) 解决方案:这通是由于配置文件中的数据源相关配置错误导致的。你需要确保你的数据源配置正确,并且可以成功连接到数据库。 5. 错误信息:"Table 'xxx' doesn't exist"(表'xxx'不存在) 解决方案:这通是由于数据库中没有对应的表导致的。你需要确保在你的数据库中创建了正确的表,并且表名与MyBatis Plus中的映射一致。 请注意,这些只是一些见的错误和解决方案,你可能会遇到其他不同的错误。在解决这些错误,你可以仔细检查错误信息,并查阅MyBatis Plus文档或搜索相关的解决方案和示例。
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值