# 0

[https://www.udemy.com/spring-hibernate-tutorial/learn/v4/content](https://www.udemy.com/spring-hibernate-tutorial/learn/v4/content)

* inversion of control
* dependency injection

## 1. Spring Container

### 1.1 Primary functions

*
  * Create and manage object(Inversion of Control)
*
  * Inject object's dependencies(Dependency Injection)

### 1.2 Configuring Spring Container

*
  * XML configuration file(legacy, but most legacy apps still use this)
*
  * Java Annotations(modern)
*
  * Java Source Code(modern)

## 2. Spring Development Process--Inversion of control

1. Configure your Spring Beans &#x20;
2. Create a Spring Container &#x20;
3. Retrieve Beans from Spring Container

Step2: Create a Spring Container

* Spring container is generically known as ApplicationContext
* Specialized implementations
  * ClassPathXmlApplicationContext: helps to fetch beans defined in xml. ClassPathXmlApplicationContext loads xml files from the classpath.
  * AnnotationConfigApplicationContext
  * GenericWebApplicationContext
  * others....

## e.g. XML configuration file![](https://3099538882-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LgDoNu9xsh-xPMjwvdG%2F-LgDoQeAFLWsrLlugmDB%2F-LgDoS3iYHFieLTPF73u%2Fspring-hibernate-tutorial.jpg?generation=1559321765144112\&alt=media)3. Dependency Injection

There are many types of Injections with Spring, the two most common are: **Constructor Injection** and **Setter Injection.**

## 3.1 Development process--Constructor Injection

1. Define the dependency interface and class.
2. Create a constructor in your class for Injections
3. Configure the dependency injection in Spring config file

## 3.2 Development process--Setter Injection

1. Create setter methods in your class for Injections
2. Configure the dependency injection in Spring config file![](https://3099538882-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LgDoNu9xsh-xPMjwvdG%2F-LgDoQeAFLWsrLlugmDB%2F-LgDoS3kll1ojLJ0OKlD%2F2.jpg?generation=1559321771778810\&alt=media)

## 3.3 Injecting Literal Values

#### development process--injecting literal values

1. Create setter methods in your class for Injections
2. Configure the dependency injection in Spring config file![](https://3099538882-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LgDoNu9xsh-xPMjwvdG%2F-LgDoQeAFLWsrLlugmDB%2F-LgDoS3mJ0RTl__yyCfr%2F3.jpg?generation=1559321764880712\&alt=media)

## 3.4 Injecting Values from a Properties File

### development process

1. Create Properties File
2. Load Properties File in Spring config file
3. Reference values from Properties File

![](https://3099538882-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LgDoNu9xsh-xPMjwvdG%2F-LgDoQeAFLWsrLlugmDB%2F-LgDoS3oyVKthnVyqcDV%2F1.jpg?generation=1559321771824245\&alt=media)![](https://3099538882-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LgDoNu9xsh-xPMjwvdG%2F-LgDoQeAFLWsrLlugmDB%2F-LgDoS3qrMooY8nCFrv4%2F5.jpg?generation=1559321765239031\&alt=media)
