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

编程知识 更新时间:2023-05-02 05:28:18

报错信息如下

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: 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);
    }
}

更多推荐

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

本文发布于:2023-04-26 06:25:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/08a622fb0e91edc3f784444a47cad2b2.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:报错   bean   defining   MyBatis   configuration

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 104475文章数
  • 26215阅读数
  • 0评论数