MyBatis解决Consider defining a bean of type 'XXXX'in your configuration.报错

报错信息如下

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.2.2.RELEASE)

2020-01-11 15:56:15.154  INFO 58552 --- [           main] com.project.demo.DemoApplication           : Starting DemoApplication on PC-20180323TDYI with PID 58552 (started by Administrator in D:\intellij workspace\demo)
2020-01-11 15:56:15.160  INFO 58552 --- [           main] com.project.demo.DemoApplication           : No active profile set, falling back to default profiles: default
2020-01-11 15:56:16.154  WARN 58552 --- [           main] o.m.s.mapper.ClassPathMapperScanner      : No MyBatis mapper was found in '[com.project.demo.mapper]' package. Please check your configuration.
2020-01-11 15:56:16.764  INFO 58552 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2020-01-11 15:56:16.776  INFO 58552 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2020-01-11 15:56:16.777  INFO 58552 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.29]
2020-01-11 15:56:17.382  INFO 58552 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2020-01-11 15:56:17.382  INFO 58552 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 2067 ms
2020-01-11 15:56:17.573  WARN 58552 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'musController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'musService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.project.demo.ext.mapper.UserBeanExtMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@javax.annotation.Resource(shareable=true, lookup="", name="", description="", authenticationType=CONTAINER, type=java.lang.Object.class, mappedName="")}
2020-01-11 15:56:17.577  INFO 58552 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2020-01-11 15:56:17.877  INFO 58552 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-01-11 15:56:18.102 ERROR 58552 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

A component required a bean of type 'com.project.demo.ext.mapper.UserBeanExtMapper' that could not be found.


Action:

Consider defining a bean of type 'com.project.demo.ext.mapper.UserBeanExtMapper' in your configuration.


Process finished with exit code 1

因为我在idea里更换了一下bean盒mapper的目录,增加了ext目录存放实际使用的文件,idea帮你把很多目录都改过来了,我自己只修改了application.yml里的这个地方

mybatis:
  mapper-locations: classpath:ext/mapper/*.xml  #注意:一定要对应mapper映射xml文件的所在路径
  type-aliases-package: com.project.demo.ext.entity  # 注意:对应实体类的路径

所以遗漏了一处MapperScan注解的修改
@MapperScan(value=“com.project.demo.mapper”)
改为
@MapperScan(value=“com.project.demo.ext.mapper”)

package com.project.demo;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@MapperScan(value="com.project.demo.ext.mapper")
@SpringBootApplication
public class DemoApplication {
    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值