Annotation-specified bean name 'xxx' for bean class [com.xxx.xxx.xxx] conflicts with existing

The following error occurs when the server is started:
Annotation-specified bean name 'userMapper' for bean class [com.promote.website.mapper.UserMapper] conflicts with existing, non-compatible bean definition of same name and class [com.promote.user.mapper] .UserMapper]
Google Translate:
Annotation for Bean class [com.promote.website.mapper.UserMapper] specifies a bean name 'userMapper' that is incompatible with an existing one of the same name and class [com.promote.user.mapper.UserMapper] Bean definition conflict

After the Spring container turns on annotation scanning, it will scan the beans under all packages that meet the configuration conditions when the server starts, and create and manage bean objects. The above error is mainly due to the duplication of bean names in the Spring container.

Spring does not support settings with the same class name in different packages. This is because the default Spring retrieved bean's unique ID (name attribute in @Service, @Component, etc. annotations) is the class name (Class Name) and does not contain package name (Package Name) information.

Solution:

  1. Directly modify the class name of the same bean, and the error message will indicate which bean is duplicated.
  2. Paths can be refined during annotation scanning.

Guess you like

Origin blog.csdn.net/weixin_40307206/article/details/103548812