springboot 工程启动报错之Consider defining a bean of type ‘XXX’ in your configuration.

一、前言:

使用springboot自动注入的方式搭建好了工程,结果启动的时候报错了!!!,错误如下图:

Description:

Field userEntityMapper in com.xxx.xxx.service.UserService required a bean of type ‘com.xxx.xxx.dao.UserEntityMapper‘ that could not be found.

Action:

Consider defining a bean of type ‘com.xxx.xxx.dao.UserEntityMapper‘ in your configuration.

二、解决方式:

1.检查自己写的注解是否错了,并没有。

2.在网上查找解决方式:如下所示:

步骤一:

  在springboot的配置文件添加,mybatis的配置如下所示:

mybatis:
  typeAliasesPackage: com.xxx.xxx.dao.entity
  mapperLocations: classpath:mapper/*.xml

步骤二:

  ①将接口与对应的实现类放在与application启动类的同一个目录或者他的子目录下,这样注解可以被扫描到,这是最省事的办法。(没测试)
  ②或者在启动类上加上@MapperScan或者@ComponentScan注解,手动指定application类要扫描哪些包下的注解,如下所示:

@SpringBootApplication
@ComponentScan(basePackages = {"com.xxx.xxx.dao"})

  ③或者在接口上添加@Mapper注解。

@Mapper
public interface UserMapper {
}

ps:之所以没有找到对应的Bean是因为,@SpringBootApplication没有扫描到。

原文地址:https://www.cnblogs.com/wasbg/p/11416507.html

时间: 2024-08-05 10:03:04

springboot 工程启动报错之Consider defining a bean of type ‘XXX’ in your configuration.的相关文章

启动项目,编译报错:Consider defining a bean of type 'XXX' in your configuration.

在controller层注入ConfigBean,编译器报错: 一开是以为是intellij idea 的告警级别设定的问题,就没有在意,继续启动项目,结果控制台报错:Consider defining a bean of type 'XXX' in your configuration. 错误信息显示找不到这个Bean类. 但是我明明写了啊. 后来经过一番查找,大概有了如下理解:主要问题出在@SpringBootApplication 这个注解上. 点进这个注解,可以看到,此注解功能大概由下面

【spring boot】mybatis启动报错:Consider defining a bean of type 'com.newhope.interview.dao.UserMapper' in your configuration.

启动报错: 2018-02-24 22:41:00.442 WARN 2952 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error c

spring boot注入error,Consider defining a bean of type 'xxx' in your configuration问题解决方案

经常出现这问题一定是非spring生态圈的@标签 没被spring引入,如mybatis等 因为在默认情况下只能扫描与控制器在同一个包下以及其子包下的@Component注解,以及能将指定注解的类自动注册为Bean的@[email protected]和@ Repository 那个这个时候就需要@ComponentScan或者@MapperScan了 要是xml配置注入有这问题,麻烦一遍一遍看xml文件的配置,绝对是哪里没写匹配. spring boot注入error,Consider def

Consider defining a bean of type `xxx` in your configuration问题解决问题解决

在使用SpringBoot装配mybatis时出现了异常 *************************** APPLICATION FAILED TO START *************************** Description: Field studentService in com.example.demo.action.StudentController required a bean of type 'com.example.demo.service.StudentS

springboot项目启动报错 url' attribute is not specified and no embedded datasource could be configured

报错相关信息: 2019-07-22 17:12:48.971 ERROR 8312 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPLICATION FAILED TO START *************************** Description: Failed to configure a DataSource: 'url' attribute is not

第一个springboot项目启动报错Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

报错内容具体如下 *************************** APPLICATION FAILED TO START *************************** Description: Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured. Reason: Failed to determine a

Consider defining a bean of type 'package' in your configuration [Spring-Boot]

https://stackoverflow.com/questions/40384056/consider-defining-a-bean-of-type-package-in-your-configuration-spring-boot Your Applicant class is not scanned it seems. By default all packages starting with the root as the class where you have put @Spri

spring注入时报错::No qualifying bean of type 'xxx.xxMapper'

做一个小项目,因为有 baseService,所以偷懒就没有写单独的每个xxService接口,直接写的xxServiceImpl,结果在service实现类中注入Mapper的时候,用的 @Autowired, 结果,junit一启动,就报错误:Java.lang.illegalStateException:Failed to load ApplicationContext 具体是在 创建bean的时候报:No qualifying bean of type 'xxx.xxMapper' ab

spring-boot:run启动报错

Intellij Idea中的spring boot项目,使用main方法运行可以启动,但是使用mvn spring-boot:run启动总是报错 大概意思就是找不到类:org/apache/maven/shared/artifact/filter/collection/ArtifactsFilter 原来是没有在仓库中找到对应的插件,指定一个找得到的版本号即可解决 <build> <plugins> <plugin> <groupId>org.spring