Spring Boot @Autowired无法注入类 Consider defining a bean of type

SpringBoot 装备默认规则是根据Application类所在的包位置从上到下扫描,

例如

com.seed.controller
com.seed.service
com.seed.dao

如果 Application在com.seed.controller 这个包下, 就会无法扫描 service dao, 所以可以看到 很多博客写的spring整合mybatis 都在一个包下。

如果把Application 放在com.seed下 就可以扫描到其子包 service dao

就这个小问题卡了我3个小时。。。 囧。。。 希望各位技术大牛朋友写博客的时候一定要肉身尝试。把一些坑都告诉大家。

原文地址:https://www.cnblogs.com/marsamoeba/p/8979526.html

时间: 2024-10-01 02:07:12

Spring Boot @Autowired无法注入类 Consider defining a bean of type的相关文章

【Spring Boot】Spring Boot之使用ImportBeanDefinitionRegistrar类实现动态注册Bean

一.ImportBeanDefinitionRegistrar类介绍 ImportBeanDefinitionRegistrar类通过其他@Configuration类通过@Import的方式来加载,通常是启动类或配置类. 然后会调用该接口方法,将其中要注册的类注册成bean. 通过实现该接口的类拥有注册bean的能力. 可以实现遗下Aware接口 EnvironmentAware BeanFactoryAware BeanClassLoaderAware ResourceLoaderAware

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 数据库出现 Consider defining a bean of type 'com.jc.wechat.app.dao.ClientRepository' in your configuration. 解决办法

错误日志完整: Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.2020-01-02 12:50:10.767 ERROR 8624 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter : ***************************APPLICATION FA

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

【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

启动项目,编译报错: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 这个注解上. 点进这个注解,可以看到,此注解功能大概由下面

Consider defining a bean of type 'com.lvjing.dao.DeviceStatusMapper' in your configuration.

"C:\Program Files\Java\jdk1.8.0_181\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2018.2.4\lib\idea_rt.jar=55273:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2018.2.4\bin" -Dfile.enc

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 '

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