Fundamentals
Dependency Injection and IOC
DI is a design pattern. Spring handles creation and linking dependencies. Constructors and setters to link dependencies.
Advantages
Having a loosely coupled systems. Easy use of mocked objects. Easily testable application. Separates the framework API and dependant objects. Reusability and readable objects.
IOC in Java
XML and Java (@Configuration) DI.
Annotations: @Autowired, @Quialifier, @Component
application-context.xml (ClassPathXmlApplicationContext.class) in src/main/resources
XML Configuration
Example setter injection:
Example constructor injection:
Java Configuration
fdf
Bean
Java class defined in XML file.
@Qualifier when using a specific imlementacion of an interface.
Into XML fiile: <bean...>
Interfaces
They are contracts. No need to know implementation. Template based programming design approach.