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

異常:org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name

這篇具有很好參考價(jià)值的文章主要介紹了異常:org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

項(xiàng)目場(chǎng)景:SpringBoot+Mybatis。

出現(xiàn)這種異常主要是無(wú)法創(chuàng)建bean到容器中,主要有以下幾種情況:

1.注解沒(méi)有添加:

controller:

@RestController
@AllArgsConstructor
@RequestMapping("/enterprise")
@Api(value = "企業(yè)數(shù)據(jù)", tags = "企業(yè)數(shù)據(jù)接口")
public class EnterpriseController {
	private final IEnterpriseService service;
}

注:

  • controller類(lèi)要加入@RestController注解,@AllArgsConstructor注解視情況而定。
  • 引入了private final IEnterpriseService service,所以需要注入,可以在controller類(lèi)上加入@AllArgsConstrctor注解修飾。
  • 或者用@Autowired修飾注入變量。
    @Autowired
	private final IEnterpriseService service;

service:

@Service
@AllArgsConstructor
public class EnterpriseServiceImpl extends BaseServiceImpl<EnterpriseMapper, Enterprise> implements IEnterpriseService {
	
	public List<Map> countByType() {
		return baseMapper.countByType();
	}
}

注:

  • service層要加入@Service注解。
  • 如果service層中引入了Mapper變量,則需要加入@AllArgsConstrctor注解;當(dāng)然也可以用@Autowired注解修飾變量。不過(guò)推薦使用@AllArgsConstrctor注解,因?yàn)橹恍枰陬?lèi)上引入一次;使用@Autowired注解需要修飾每一個(gè)引入的Mapper,極其繁瑣。
@Service
public class EnterpriseServiceImpl extends BaseServiceImpl<EnterpriseMapper, Enterprise> implements IEnterpriseService {

    @Autowired
	private final EnterpriseMapper mapper;

    @Autowired
	private final BlogMapper mapper;

	public List<Map> countByType() {
		return baseMapper.countByType();
	}
}

2.接口有沒(méi)有對(duì)應(yīng)的實(shí)現(xiàn)類(lèi),以及實(shí)現(xiàn)類(lèi)實(shí)現(xiàn)的接口是否正確。

3.項(xiàng)目中的文件是否重名,全局定位異常文件,并修改為不同文件名。

4.啟動(dòng)類(lèi)中注解是否掃描到所有mapper。

@EnableScheduling
@SpringBootApplication
@ComponentScan({"org.springblade","com.hello","com.test"})
@MapperScan({"com.hello.**.mapper.**","com.test.**.mapper.**"})
public class Application {

	public static void main(String[] args) {
		BladeApplication.run(CommonConstant.APPLICATION_NAME, Application.class, args);

	}

}

注:

  • @ComponentScan注解和@MapperScan注解一定要掃描到所有文件路徑,多個(gè)路徑之間用逗號(hào)分隔開(kāi)。
  • 或者在yml配置文件中配置mapper掃描路徑。

5.Mapper.xml文件中配置的resultMap對(duì)應(yīng)的實(shí)體類(lèi)路徑是否正確,以及各種Mybatis標(biāo)簽對(duì)應(yīng)的resultMap或者resultType路徑是否正確。

6.接口對(duì)應(yīng)的地址是否重復(fù)。如下圖,兩個(gè)接口均使用了相同的地址,會(huì)出現(xiàn)異常。


	@GetMapping("/count")
	public R<EnterpriseVO> test(@RequestBody  Enterprise enterprise){
		EnterpriseVO detail = service.test(enterprise);
		return R.data(detail);
	}
	
	@PostMapping("/count")
	public R<Enterprise> update(@RequestBody Enterprise enterprise){
		boolean flag = service.updateByBody(enterprise);
		Enterprise entity = service.selectInfo(enterprise);
		return R.data(entity);
	}

異常排查技巧:

通常出現(xiàn)這種異常會(huì)在控制臺(tái)打印出一堆異常信息,在控制臺(tái)上方的異常信息大多是和程序真正的問(wèn)題沒(méi)有直接關(guān)系的,這里給出以下異常排查技巧:文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-833800.html

  1. 控制臺(tái)看報(bào)錯(cuò):從下往上看。
  2. 利用好idea的全局搜索定位功能去排查異常。

到了這里,關(guān)于異常:org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

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

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

相關(guān)文章

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

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

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包