问题记录:启动报错Field Mapper in ServiceImpl required a bean of type ‘Mapper‘ that could not be found

SpringBoot项目启动报错:Field Mapper in ServiceImpl required a bean of type ‘Mapper‘ that could not be found

1.报错:

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-06-15 15:39:21.068 ERROR 3720 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

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

Description:

Field userMapper in com.example.demo.service.impl.UserServiceImpl required a bean of type 'com.example.demo.mapper.UserMapper' that could not be found.

The injection point has the following annotations:
	- @org.springframework.beans.factory.annotation.Autowired(required=true)


Action:

Consider defining a bean of type 'com.example.demo.mapper.UserMapper' in your configuration.


Process finished with exit code 1

2.原因:没有找到mapper包
3.解决:启动类加入注解@MapperScan ,路径是mapper所在的包

package com.example.demo;

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

@MapperScan("com.example.demo.mapper")
@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

}

4.重新启动,问题解决

2021-06-15 16:46:04.370  INFO 9908 --- [           main] com.example.demo.DemoApplication         : No active profile set, falling back to default profiles: default
2021-06-15 16:46:05.090  INFO 9908 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2021-06-15 16:46:05.096  INFO 9908 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-06-15 16:46:05.096  INFO 9908 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.46]
2021-06-15 16:46:05.144  INFO 9908 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2021-06-15 16:46:05.144  INFO 9908 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 735 ms
2021-06-15 16:46:05.385  INFO 9908 --- [           main] o.s.b.a.w.s.WelcomePageHandlerMapping    : Adding welcome page template: index
2021-06-15 16:46:05.507  INFO 9908 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2021-06-15 16:46:05.515  INFO 9908 --- [           main] com.example.demo.DemoApplication         : Started DemoApplication in 1.443 seconds (JVM running for 1.942)
2021-06-15 16:46:05.516  INFO 9908 --- [           main] o.s.b.a.ApplicationAvailabilityBean      : Application availability state LivenessState changed to CORRECT
2021-06-15 16:46:05.517  INFO 9908 --- [           main] o.s.b.a.ApplicationAvailabilityBean      : Application availability state ReadinessState changed to ACCEPTING_TRAFFIC

  • 4
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值