Our application is split into two layers. There is the core layer (a layer that is common between multiple projects) and there is the customer/customization layer (layer that is customized per customer). What is needed is to enable the customer layer to override the core dao repository. This means that if in the core there is a dao:
3.Restricts by Qualifiers (ignored if match is found by name)
The problem is as follows. Client code is as follows:
Private UserDao useDao;
The spring component uses the @Repository annotation for the definition. This annotation is used without a name, so the default name is for the core: userHibernateDao and for the customer: userHibernateDaoEx. When spring tries to inject into userDao using the @Resource, it does not find any component by the name of userDao. Spring then searches by type of UserDao, and finds two implementations and cannot inject the component. By giving the same name to both components spring will complain that there are two components with the same id.
The solution is to use an undocumented feature of spring. You cannot define two components with the same id in the same xml file. But if you can define two beans with the same id in two different xml files, the second bean (depends on the order of the files) will be the one that spring uses.
So in the customer layer, instead of using the @Repository annotation on the inherited dao, it needs to be defined in an xml file.
We have found a way for the customer layer to inherit and override a spring bean that has been defined in the core layer in such a way that the new bean definied in the customer layer will be used by the core layer itself and the overridden functionality from the customer layer.