CDI has a Specialization feature, and I'm looking for it in the Spring world.
Details In CDI, the @Specializes annotation allows @Specializes to change the behavior of a bean only by overriding it. It is completely transparent to users of this bean, for example. if we had
public class OneBean { public String whoAmI() { return "OneBean"; } } @Specializes public class AnotherBean extends OneBean { @Override public String whoAmI() { return "AnotherBean"; } }
we could
public class SomewhereElse { @Inject OneBean oneBean;
It becomes really useful once OneBean actually used with and without AnotherBean . For example, if OneBean is in one.jar and AnotherBean is in another.jar , we can only change the behavior of the bean by reconfiguring the class path.
Question. Is there something like specialization in Spring?
I could only find the @Primary annotation, which, however, has different semantics: @Primary does not replace one bean, but only marks one of several alternatives as primary. Especially, as I understand it, I could not build a hierarchy of deep inheritance, as far as possible, using @Specializes .
spring subclass cdi specialization
fxnn
source share