• 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

  • 相关阅读:
    陶瓷电容的结构、工艺、失效模式
    Vue.js最佳实践
    Vue 超快速学习
    CSS 小技巧
    HTML5 Canvas
    webkit下面的CSS设置滚动条
    Some untracked working tree files would be overwritten by checkout. Please move or remove them before you can checkout. View them
    JSCS: Please specify path to 'JSCS' package
    React中ref的使用方法
    React 60S倒计时
  • 原文地址:https://www.cnblogs.com/xing-nb/p/12146175.html
Copyright © 2020-2023  润新知