The act of creating associations between objects is the essence of dependency injections and is referred to as wiring.
Container is responsible for creating the beans and coordinating the relationships between them.
There are 3 primary wiring mechanisms:
– config in XML
– config in Java
– automatic wiring
2. Wiring beans automatically
Two angles of automatic wiring:
– component scanning – automatically discovers beans to be created in the application context
– autowiring – automatically satisfies bean dependencies
@Component – identifies this class as a component class and serves as a clue that bean should be created for this class
@ComponentScan – enables component scanning. Spring scans this package and any subpackages looking for classes annotated with @Component. In XML use .
@Configuration – this class is Java based configuration
Naming a component-scanned bean
Bean ID is derived from its class name, lowering the first letter of the class name. If you would like to have a different ID, pass it as a value to @Component(“desiredId”). Alternative way is to use @Named(“desiredId”).
@ContextConfiguration(classes=SomeClass.class) – load configuration from this class