יום שלישי, 6 במאי 2014

Spring inheritance tree

With Spring you can collect classes and there inherits tree into list .
For an example :
Use the autowire spring context declaration:
@Configuration
@ComponentScan("com.model.cars")
public class SpringContext {
}

We can declare a ctor in a @component Road class
 @Autowired
public Road(List<Car> pCar) {
 
}
The auto wired process scans the  com.model.cars directory for all the components that inherit from Car class (and the car class itself if exists in the scanning directory )  and construct the car Ctor parameter pCar list accordingly .
So if the com.model.cars path contains the following component
@Component
Class sosita extends Car
and
@Component
Class Subaru extends
sosita
The  Road ctor will be called with a 2 items list of sosita and Subaru

Reference:
http://lkrnac.net/blog/2014/04/30/load-inheritance-tree/

אין תגובות:

הוסף רשומת תגובה