springboot启动时候的一个注意事项——不同包下有同样名字的class类

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。



猜你喜欢

转载自blog.csdn.net/zuixiaoyao_001/article/details/80245170