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。