欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

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

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

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

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

解決辦法

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

再次啟動,OK。

springboot不同包下同名文件,啟動時報重名錯誤的解決

錯誤信息:

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的命名策略,結果不起作用。

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

解決辦法

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

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

2、StarterApplication中添加

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

完美!

總結

以上為個人經驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關文章

最新評論