How to Solve Spring Bean Same Name Conflict

When springboot is started, it often fails to start. It is found that there are services and serviceimpl with the same name under different packages. It is reasonable to say that there can be classes with the same name under different packages, but it cannot be started. An error is reported

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]

Meaning: the class [com. Example. Service. Roleserviceimpl] annotated with bean name ‘roleserviceimpl’ conflicts with the existing incompatible class with the same name [com.Example.Roleservice.Roleserviceimpl].

It turns out that the annotation @service is only used on these two implementation classes. According to the mapping rules, these two services are mapped to roleserviceimpl, which conflicts.

Solution:

1. change one of the implementation classes to a different name;

2: change one of the annotations to an annotation @service (name = “AAAA”) whose name is non roleserviceimpl.

Start again, OK.

Similar Posts: