国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

【Spring常見錯誤】No qualifying bean of type

這篇具有很好參考價值的文章主要介紹了【Spring常見錯誤】No qualifying bean of type。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

報錯信息:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.ssmpdemo.ServiceTest': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.ssmpdemo.service.UserService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations:

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.ssmpdemo.service.UserService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations:?
?

對癥下藥:

很明顯,錯誤原因為SpringBoot自動注入Bean找不到相對應(yīng)的Bean類型。導(dǎo)致自動注入失敗。

既然發(fā)現(xiàn)錯誤就對癥下藥,找對應(yīng)的Bean,這里找的是Service對應(yīng)的實現(xiàn)類

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ssmpdemo.entity.User;
import com.ssmpdemo.mapper.UserMapper;
import com.ssmpdemo.service.UserService;

public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
}

發(fā)現(xiàn)對應(yīng)的實現(xiàn)類開頭未加注解:(如果注解已加,可在相關(guān)問題找找是否有對應(yīng)的問題)

問題解決:

@Controller、@Service、@Repository、 @Component 加上其中一個。

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ssmpdemo.entity.User;
import com.ssmpdemo.mapper.UserMapper;
import com.ssmpdemo.service.UserService;
import org.springframework.stereotype.Repository;

@Repository
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
}

相關(guān)問題:

包目錄不對應(yīng)

例如:Application所在包:com.spring.demo

這時Spring只會掃描demo目錄下的所有文件,如果需要的Bean不在此目錄下,自然注入失敗。

只需將Bean移動到Application所在目錄下即可。

????作者主頁:??求不脫發(fā)的博客

???? 精選專欄:??SSM直擊大廠

???? 精彩摘要:MyBatis 核心配置文件(xxxConfig.xml),該文件配置了MyBatis的一些全局信息,,包含數(shù)據(jù)庫連接信息和MyBatis運(yùn)行時所需的各種特性,以及設(shè)置和響應(yīng)MyBatis行為的一些屬性。本文將深入淺出的介紹MyBatis核心配置文件中常用的標(biāo)簽配置。

????覺得文章還不錯的話歡迎大家點贊???收藏???評論??支持博主??文章來源地址http://www.zghlxwxcb.cn/news/detail-403983.html

到了這里,關(guān)于【Spring常見錯誤】No qualifying bean of type的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進(jìn)行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • No qualifying bean of type ‘org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate‘ a

    No qualifying bean of type ‘org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate’ available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 提示找不到 ElasticsearchRestTemplate 寫一個配置類注入

    2024年02月17日
    瀏覽(19)
  • 項目依賴問題導(dǎo)致No qualifying bean of type 'org.apache.ibatis.session.SqlSessionFactory' available: more tha...

    A項目之前一直都是好好的,但是某天下午啟動的時候報錯,報錯見下,報錯原因是org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type \\\'org.apache.ibatis.session.SqlSessionFactory\\\' available: more than one \\\'primary\\\' bean found among candidates。? 初步定位這個問題的時候眼睛一直

    2023年04月09日
    瀏覽(16)
  • SpringBoot - 在IDEA中經(jīng)常發(fā)現(xiàn):Could not autowire. No beans of ‘xxx‘ type found的錯誤

    SpringBoot - 在IDEA中經(jīng)常發(fā)現(xiàn):Could not autowire. No beans of ‘xxx‘ type found的錯誤

    錯誤描述 在SPRINGBOOT的項目中,使用IDEA時經(jīng)常會遇到Could not autowire. No beans of ‘xxxx’ type found的錯誤提示,但是程序的編譯和運(yùn)行都沒有問題,這個錯誤提示并不影響項目的生產(chǎn)。 解決方案

    2024年02月15日
    瀏覽(23)
  • Could not autowire. No beans of ‘DiscoveryClient‘ type found.

    Could not autowire. No beans of ‘DiscoveryClient‘ type found.

    一、導(dǎo)錯了包 DiscoveryClient對應(yīng)有兩個包: org.springframework.cloud.client.discovery.DiscoveryClient; com.netflix.discovery.DiscoveryClient; 目前導(dǎo)入的包是: 改成第一個包,發(fā)現(xiàn)不再報紅了。

    2024年02月11日
    瀏覽(30)
  • @Autowired報錯Could not autowire. No beans of ‘XXX‘ type found

    @Autowired報錯Could not autowire. No beans of ‘XXX‘ type found

    ??IDEA中使用 @Autowired 報錯 Could not autowire. No beans of \\\'XXX\\\' type found ,錯誤大致意思為:沒有匹配到類型為XXX的bean。 ??個人覺得,注入 controller 的 service 雖然一般來說我們都是注入一個接口,但是該接口有實現(xiàn)類,并且使用 @Service 進(jìn)行關(guān)聯(lián),所以注入類型應(yīng)該也可以視為一

    2024年02月07日
    瀏覽(24)
  • idea報錯:Could not autowire. No beans of ‘UserService‘ type found.

    點個關(guān)注,必回關(guān) 翻譯:無法自動連線。未找到“用戶服務(wù)”類型的服務(wù)類。 當(dāng)報錯之后idea會提示錯誤,不過程序的編譯和運(yùn)行都是沒有問題的(這個錯誤提示不會產(chǎn)生任何印象) 解決方案 解決方案1: Settings - Editor - Inspections - Spring - Spring Core - Code - Autowiring for Bean Class

    2024年02月11日
    瀏覽(24)
  • idea報“Could not autowire. No beans of ‘UserMapper‘ type found. ”錯解決辦法

    idea報“Could not autowire. No beans of ‘UserMapper‘ type found. ”錯解決辦法

    idea具有檢測功能,接口不能直接創(chuàng)建bean的,需要用動態(tài)代理技術(shù)來解決。 1.修改idea的配置 1.點擊file,選擇setting 2.搜索inspections,找到Spring 3.找到Spring子目錄下的Springcore 4.在Springcore的子目錄下找到code 5.把seyerity選項改成警告 2.修改代碼 1,@Autowrited改為@Autowrited(required = false)

    2024年02月05日
    瀏覽(25)
  • IDEA提示找不到Mapper接口:Could not autowire.No beans of ‘xxxMapper‘ type found

    IDEA提示找不到Mapper接口:Could not autowire.No beans of ‘xxxMapper‘ type found

    我們可以看到,上面的紅色警告在提示我們,找不到 xxxMaper 這個類型的 bean。 為啥呢? 因為 @Mapper 這個注解是 Mybatis 提供的,而 @Autowried 注解是 Spring 提供的,IDEA能理解 Spring 的上下文,但是卻和 Mybatis 關(guān)聯(lián)不上。而且我們可以根據(jù) @Autowried 源碼看到,默認(rèn)情況下,@Autowri

    2024年02月08日
    瀏覽(24)
  • 解決SpringBoot項目中的報錯:Could not autowire,no beans of “XXX“ type found

    解決SpringBoot項目中的報錯:Could not autowire,no beans of “XXX“ type found

    問題:找不到mapper注入的bean,如圖 ? 分析:注入mapper有兩種方式: ?第一種:在啟動類中添加? @MapperScan ???????然后在mapper的類中添加? @Repository 注解 第二種方法:直接在各個mapper類中添加@Mapper注解,但是一定要注意導(dǎo)入正確的包,否則解決不了這個異常; ?很多新手

    2024年02月08日
    瀏覽(33)
  • 【錯誤】A component required a bean of type ‘org.springframework.security.config.annotation.ObjectPostPr

    【錯誤】A component required a bean of type ‘org.springframework.security.config.annotation.ObjectPostPr

    Description: A component required a bean of type \\\'org.springframework.security.config.annotation.ObjectPostProcessor\\\' that could not be found. Action: Consider defining a bean of type \\\'org.springframework.security.config.annotation.ObjectPostProcessor\\\' in your configuration. ? 描述: 組件需要“org.springframework.security.configannotation”類型的

    2024年02月13日
    瀏覽(22)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包