I found a solution, there is
@Primary
annotation that can be used to specify that the custom code added should be loaded instead of the original code.
Pregunta
I have a project where I use heavily autowiring, e.g.
@Component("componentA")
public class ComponentAImpl implements ComponentA
@Component("componentB")
public class ComponentBImpl implements ComponentB {
@Autowired
private ComponentA componentA;
}
But I want customer to extend all the classes, so ideally they would just add a single jar into the classpath the the extended class should be used instead of the original one. What I think would be great if they could just set a different name for the bean, e.g.
@component("componentA-custom)
I just need some way to customize the autowire process to look for a bean with "-custom" at the end and load it instead of the original bean. Is there any way to do that?
Any help appreciated. Thank you, Mariusz
Solución
I found a solution, there is
@Primary
annotation that can be used to specify that the custom code added should be loaded instead of the original code.
Otros consejos
What you are looking for is something similiar to this.
This should help you solve your problem.
If you need to get the bean name, you can inject in an instance of applicationContext which will get you the correct bean name (through a reverse lookup). or force all beans (ComponentA and CustomImplementation) to implement BeanNameAware
What You are asking about can be done via @Qualifier
annotation, but it cannot generate bean names dynamically.
To allow external beans, You will need to create XML configuration for this, as it overrides annotation - based configuration. Your customers would have to provide: