IntelliJ Idea报错Could not autowire. No beans of 'xxxx' type found的错误提示,并且编译运行时报错解决方案

在使用springboot整合mybatis的时候,在控制器中使用自动注入来注入一个mapper出现了Could not autowire. No beans of 'xxxx' type found报错,提示不能够自动注入bean。其实该问题如果编译运行程序不报错正常运行的话那么可能只是intellij idea的问题,如果不能够正常的编译运行,则可能是spring auto scan配置,在编辑情况下,无法找不到对应的bean,于是提示找不到对应bean的错误。

1、针对于可以正常编译运行但还是出现错误提示的解决方案:降低Autowired检测的级别,将Severity的级别由之前的error改成warning或其它可以忽略的级别。

 

2、针对于不能够正常编译运行的解决方案:正确的导入包,如果是检查错误提示中的类的包是否导入正确,这种错误最常见在mybatis中的mapper下,比如对于mybatis的的注解版或配置文件版的解决办法:

    ①.配置文件版:在全局配置文件中,配置要自动扫描进容器的包

<!-- mapper scanner configurer -->
<bean id="mapperScannerConfig" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="basePackage" value="com.wp.spring.mybatis.dao" />
    <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
</bean>

    ②.注解版:在运行的主类上加上注解:@MapperScan(value = "要自动扫描的包")-->(springboot整合mybatis的时候)。或则在mybatis项目中的mapper类上面加上注解@Mapper标识这是一个mapper,容器启动的时候就会自动加入到容器中了。示例如下:

    1.springboot主类:

    2.mybatis的mapper类:

 

 

  • 41
    点赞
  • 100
    收藏
    觉得还不错? 一键收藏
  • 12
    评论
在使用Spring Boot整合MyBatis时,出现"Could not autowire. No beans of 'DictService' type found."的错误提示,这意味着在自动注入DictService时找不到对应的bean。通常情况下,这个错误可能有以下几种解决方法。 1. 检查Bean的声明和注入:首先确保在DictService类上使用了@Component或@Service注解,以便让Spring容器扫描并创建该Bean。然后,在需要注入DictService的地方使用@Autowired或@Resource注解进行注入。 2. 检查包扫描配置:如果DictService类在默认的包扫描路径之外,需要在Spring Boot的配置类上使用@ComponentScan注解指定要扫描的包路径或使用@SpringBootApplication注解来自动扫描。 3. 检查依赖关系:确保DictService的依赖都已经正确配置并加载。可以通过检查相关的配置文件或依赖项是否正确导入。 4. 检查MyBatis配置:如果DictService是一个MyBatis的Mapper接口,需要确保在MyBatis的配置文件中正确配置了Mapper扫描路径,并且对应的Mapper XML文件已经正确映射。 综上所述,你可以按照以上方法逐个检查,找出造成"Could not autowire. No beans of 'DictService' type found."的原因,并进行相应的修复。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Could not autowire.No beans of ‘XXXXtype found的解决方法(详细解析其用法注解)](https://blog.csdn.net/qq_42381317/article/details/108283395)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [IntelliJ Idea报错Could not ... No beans of 'xxxx' type found的错误提示,并且编译运行时报错解决方案](https://blog.csdn.net/Hellowenpan/article/details/85249679)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [Idea 解决 Could not autowire. No beans of 'xxxx' type found 的错误提示](https://download.csdn.net/download/weixin_38632624/12751965)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值