最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

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

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

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]相沖突。

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

解決辦法

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

再次啟動,OK。

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

錯誤信息:

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,就差一個版本,就沒有FullyQualifiedAnnotationBeanNameGenerator)

2、StarterApplication中添加

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

完美!

總結(jié)

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

相關(guān)文章

最新評論

都昌县| 苏州市| 日照市| 丰台区| 祁东县| 德州市| 额尔古纳市| 千阳县| 馆陶县| 寿宁县| 固镇县| 牙克石市| 新蔡县| 万源市| 循化| 寿光市| 资兴市| 沁阳市| 正宁县| 湖州市| 城口县| 凉山| 丹凤县| 昭通市| 古交市| 喜德县| 金塔县| 花莲县| 靖州| 温泉县| 勃利县| 梅河口市| 阿坝| 临城县| 临海市| 淮滨县| 历史| 绥滨县| 通州区| 札达县| 瑞金市|