亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

springboot啟動(dòng)的注意事項(xiàng)之不同包下有同樣名字的class類問題

 更新時(shí)間:2023年06月20日 10:20:34   作者:zuixiaoyao_001  
這篇文章主要介紹了springboot啟動(dòng)的注意事項(xiàng)之不同包下有同樣名字的class類問題,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

springboot不同包下有同樣名字的class類

springboot 在啟動(dòng)時(shí)候,常啟動(dòng)不起來,檢查發(fā)現(xiàn)是不同包下面有同名的service和serviceImpl,按理說不同包下是可以有同名的類存在的,但是啟動(dòng)就是啟動(dòng)不了,報(bào)錯(cuò)說

org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'roleServiceImpl' for bean class [com.example.service.RoleServiceImpl] conflicts with existing, non-compatible bean definition of same name and class [com.example.roleService.RoleServiceImpl]

意思是:

以Bean名字‘roleServiceImpl’注解的類[com.example.service.RoleServiceImpl]與存在的不相容的同名類[com.example.roleService.RoleServiceImpl]相沖突。

原來是在這兩個(gè)實(shí)現(xiàn)類上面都只用了@service這個(gè)注解,根據(jù)映射規(guī)則,這兩個(gè)service都映射為了roleServiceImpl,發(fā)生了沖突。

解決辦法

  • 1.將其中一個(gè)實(shí)現(xiàn)類改為不同的名字;
  • 2.將其中一個(gè)注解變更為一個(gè)name為非roleServiceImpl的注解@service(name="aaaa")。

再次啟動(dòng),OK。

springboot不同包下同名文件,啟動(dòng)時(shí)報(bào)重名錯(cuò)誤的解決

錯(cuò)誤信息:

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.***.***.StarterApplication]; nested exception is org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'discussController' for bean class [com.***.***.controller.wechat.DiscussController] conflicts with existing, non-compatible bean definition of same name and class [com.***.***.controller.web.DiscussController]

本人遇到這種問題,搞了半天,頭疼。

搜來的解決辦法

1:加:@Controller("rename") ,感覺太繁瑣。

2、重新定義Bean的命名策略,結(jié)果不起作用。

就請教了我司大牛,大牛一通操作,給出了完美解決方法,在這里感謝這位老師,也分享出來哈哈。

解決辦法

1、升級spring boot到2.2.7  升級spring到5.2.3以上

(我之前用的5.2.2,就差一個(gè)版本,就沒有FullyQualifiedAnnotationBeanNameGenerator)

2、StarterApplication中添加

@ComponentScan(value = {"com.**.**.spring", ……(此處可配置多個(gè)包)},
? ? ? ? nameGenerator = FullyQualifiedAnnotationBeanNameGenerator.class)

完美!

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論