• 解决:Field xxMapper in xx.service.impl.xxServiceImpl required a bean of type 'xx.mapper.xxMapper'


    1、启动 SpringBoot项目报错,使用的是Springboot、Spring、Mybatis连接Mysql数据库,启动SpringBoot项目报错,错误如下所示:

     1   _____      .__/      .__
     2 _/ ____\____ |__)/__  __|__|____    ____
     3    __/ __ |  |  /  /  \__    /    
     4  |  |   ___/|  | >    <|  |/ __ |   |  
     5  |__|  \___  >__|/__/\_ \__(____  /___|  /
     6            /          /       /     /
     7 
     8 
     9 2020-02-28 13:50:26.771  INFO 8720 --- [           main] c.f.n.NationalpolicyApplication          : Starting NationalpolicyApplication on DESKTOP-T450s with PID 8720 (D:iehlideaworkspace
    ationalpolicy2	argetclasses started by Aiyufei in D:iehlideaworkspace
    ationalpolicy2)
    10 2020-02-28 13:50:26.777  INFO 8720 --- [           main] c.f.n.NationalpolicyApplication          : No active profile set, falling back to default profiles: default
    11 2020-02-28 13:50:28.302  INFO 8720 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JDBC repositories in DEFAULT mode.
    12 2020-02-28 13:50:28.336  INFO 8720 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 28ms. Found 0 JDBC repository interfaces.
    13 2020-02-28 13:50:28.489  WARN 8720 --- [           main] o.m.s.mapper.ClassPathMapperScanner      : No MyBatis mapper was found in '[com.feixian.mapper]' package. Please check your configuration.
    14 2020-02-28 13:50:29.271  INFO 8720 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
    15 2020-02-28 13:50:29.292  INFO 8720 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
    16 2020-02-28 13:50:29.294  INFO 8720 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.31]
    17 2020-02-28 13:50:29.449  INFO 8720 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
    18 2020-02-28 13:50:29.449  INFO 8720 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 2428 ms
    19 2020-02-28 13:50:29.521  WARN 8720 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'repoPolicyContentController': Unsatisfied dependency expressed through field 'repoPolicyContentService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'repoPolicyContentServiceImpl': Unsatisfied dependency expressed through field 'repoPolicyContentMapper'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.feixian.nationalpolicy.mapper.RepoPolicyContentMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    20 2020-02-28 13:50:29.525  INFO 8720 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
    21 2020-02-28 13:50:29.546  INFO 8720 --- [           main] ConditionEvaluationReportLoggingListener : 
    22 
    23 Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
    24 2020-02-28 13:50:29.681 ERROR 8720 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 
    25 
    26 ***************************
    27 APPLICATION FAILED TO START
    28 ***************************
    29 
    30 Description:
    31 
    32 Field repoPolicyContentMapper in com.feixian.nationalpolicy.service.impl.RepoPolicyContentServiceImpl required a bean of type 'com.feixian.nationalpolicy.mapper.RepoPolicyContentMapper' that could not be found.
    33 
    34 The injection point has the following annotations:
    35     - @org.springframework.beans.factory.annotation.Autowired(required=true)
    36 
    37 
    38 Action:
    39 
    40 Consider defining a bean of type 'com.feixian.nationalpolicy.mapper.RepoPolicyContentMapper' in your configuration.
    41 
    42 
    43 Process finished with exit code 1

    2. 报错原因,是因为项目未扫描到 mapper 包。

    3. 解决该报错的方法,如下所示:

    在项目启动类上加注解  @MapperScan("Mapper文件所在的包"),@MapperScan 是扫描mapper类的注解,就不用在每个mapper类上加@MapperScan了。

    4、重启工程成功运行。

  • 相关阅读:
    64位win7下安装Boost 1.59.0 + boost.python 1.59.0 + gccxml + pygccxml + pyplusplus(py++)
    python量化之路:获取历史某一时刻沪深上市公司股票代码及上市时间
    《Python数据分析常用手册》一、NumPy和Pandas篇
    开启防火墙,开启相关已打开端口
    harbor安装(方便内网镜像使用)
    docker+nginx:1.18 搭建局域网文件查看器-目录索引
    docker-ce 安装
    centos7安装python3 (shell)
    批量转换音频文件s48>mp3
    harbor安装简述及故障记录
  • 原文地址:https://www.cnblogs.com/biehongli/p/12376957.html
Copyright © 2020-2023  润新知