Annotate member of class to be autowired:
class Car { @Autowire public Engine engine; }
Annotate member of class with qualifier:
class FuelEngine : Engine { ... } class ElectricEngine : Engine { ... } class HybridCar { @Autowire!FuelEngine public Engine fuelEngine; @Autowire!ElectricEngine public Engine electricEngine; }
The members of an instance of "HybridCar" will now be autowired properly, because the autowire mechanism will autowire member "fuelEngine" as if it's of type "FuelEngine". This means that the members of instance "fuelEngine" will also be autowired because the autowire mechanism knows that member "fuelEngine" is an instance of "FuelEngine"
Inject
UDA for annotating class members as candidates for autowiring.
Optionally a template parameter can be supplied to specify the type of a qualified class. The qualified type of a concrete class is used to autowire members declared by supertype. If no qualifier is supplied, the type of the member is used as qualifier.
Note: @Autowire is considered legacy, but not deprecated. Using @Inject is preferred.