- ask spring to scan @component/@configuration/@service class in specified base package
2. @configuration
- tell spring that this class defines one or more @bean
- spring will load beans into it’s context before we even request it
- this is to make sure all the beans are properly configured and application fail-fast if something goes wrong
- the default scope of spring beans is singleton, meaning that the bean will be created only once for the whole application
3. @component
- spring will: scan our application for classes annotated with @Component.
- spring will: instantiate them and inject any specified dependencies into them
4. @autowired
- auto dependency injection
5. core problem that spring resolve - DI
before
public class WelcomeController {
private WelcomeService service = new WelcomeService();
"/welcome") (
public String welcome() {
return service.retrieveWelcomeMessage();
}
}
after
public class WelcomeService {
//Bla Bla Bla
}
public class WelcomeController {
private WelcomeService service;
"/welcome") (
public String welcome() {
return service.retrieveWelcomeMessage();
}
}
6. Instantiate bean
- explicitly - use applicationContext
- implicitly - use autowire
7. spring use jackson json library to marshal object into json
8. yaml file
reference
1. sprint boot vs. spring mvc vs. spring
2. yaml file example