Recently the company project intends to modular, in fact, a reason is to be able to integrate the company's multiple business code, such as a resource XXX, two business has the management of this resource, although it is a resource, but is completely different definitions, completely different tables, different processing logic. So I'm going to make the class name the same, but the package name is different.
There is a problem here, that is, when using annotations, the resources in the two modules are called Xxxdao, which will be error when Spring starts. The error is as follows conflicts with existing, non-compatible bean definition of same name and class [Xxxxdao] something, meaning that two beans have the same name, so the start error.
The solution can only let us manually modify the bean name generation strategy, I am here directly with his implementation of the class's fully qualified name (Com.abc.dao.impl.xxxDaoImpl) as the name of the bean.
Annotationbeannamegenerator is the default generation strategy for spring, let's take a look at the source code, where the Builddefaultbeanname method is the implementation of the generated name, as follows:
String shortclassname = Classutils.getshortname (Definition.getbeanclassname ());
Return Introspector.decapitalize (Shortclassname);
This default build strategy people should know how to generate, I will not elaborate.
Here Definition.getbeanclassname () is to get the fully qualified name, Classutils.getshortname is the name of the class, and the following introspector.decapitalize actually turns the initials into lowercase.
We are going to set the fully qualified name here, we can write a new class, assuming that it is called XXX, and then inherit annotationbeannamegenerator after overriding the Builddefaultbeanname method, Return to Definition.getbeanclassname () so that our generation strategy is written.
The next step is to configure it in spring. Open a. applicationcontext.xml file and find our configuration Context:component-scan this block, add a parameter name-generator= the fully qualified name of our newly written class.
By this time the default name of all beans is set, but if we explicitly write the bean ID on the class, we will still use the name of our custom bean.
Source: http://irfen.me/spring-bean-name-gener-modify/
From for notes (Wiz)
Generation policy/Mode modification of default bean name in spring