zoukankan      html  css  js  c++  java
  • IntelliJ Idea 解决 Could not autowire. No beans of 'xxxx' type found 的错误提示

    IntelliJ Idea 解决 Could not autowire. No beans of ‘xxxx’ type found 的错误提示
    哈,在使用 @Autowired 时,今天又遇一坑,这俩波浪线是干啥子嘛:


    然鹅,试了一下,控制台也不报错,可以正常运行,


    数据也有:


    于是,又再百度上找答案。。

    问题分析
    在 Idea 的 spring 工程里,经常会遇到 Could not autowire. No beans of ‘xxxx’ type found 的错误提示。但程序的编译和运行都是没有问题的,这个错误提示并不会产生影响。但红色的错误提示在有些有强迫症的程序员眼里,多多少少有些不太舒服。

    问题原因其一
    第一个是 Intellij IDEA 本身工具的问题。

    解决办法:

    (1)不理它。

    (2)在注解上加上:

    @Autowired(required = false)
    1
    (3)降低 Autowired 检测的级别,将 Severity 的级别由之前的 error 改成 warning 或其它可以忽略的级别。

    还有一个原因
    这个博主没有遇到,友情粘贴!

    第二个便是我们导入 @Service 包的时候导入包错误造成的。

    spring auto scan 配置,在编辑情况下,无法找不到对应的bean,于是提示找不到对应 bean 的错误。常见于 mybatis 的 mapper,如下:

    <!-- mapper scanner configurer -->
    <bean id="mapperScannerConfig" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.adu.spring_test.mybatis.dao" />
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
    </bean>
    1
    2
    3
    4
    5
    解决办法:

    错误导包 import com.alibaba.dubbo.config.annotation.Service;
    1
    正确的包应该是下面这个:

    import org.springframework.stereotype.Service;
    1
    ————————————————
    版权声明:本文为CSDN博主「西瓜天尊」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/plpldog/article/details/91961101

  • 相关阅读:
    Oracle 手工创建awr快照,获取报告
    Oracle块修改跟踪功能
    Oracle 反向索引(反转建索引) 理解
    oracle聚簇表的理解 (转自:https://blog.csdn.net/gumengkai/article/details/51009345 )
    Fix the iOS code signing issue when using Jenkins
    ios系统crash文件分析
    python版本管理
    python requirements.txt
    android makefile protoc路径添加
    初识tflite源码
  • 原文地址:https://www.cnblogs.com/xing-nb/p/12146175.html
Copyright © 2011-2022 走看看