解決spring的bean同名沖突


springboot 在啟動時候,常啟動不起來,檢查發現是不同包下面有同名的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這個注解,根據映射規則,這兩個service都映射為了roleServiceImpl,發生了沖突。

解決辦法,一:將其中一個實現類改為不同的名字;

                二:將其中一個注解變更為一個name為非roleServiceImpl的注解@service(name="aaaa")。

再次啟動,OK。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM