Fundamental concept in spring framework. Spring injects dependencies into other objects enabling loose coupling of components and easy to manage/change/test dependencies.
It is a process by which objects define their dependencies through external ways such as constructors, factory methods, properties, annotations.
InitializingBean - enforces the implementing class to implement afterPropertiesSet, a method called during spring bean initialization.
DisposableBean - enforces the implementing class to implement destroy, a method called during spring container destruction.
BeanPostProcessor - enforces the implementing class to implement postProcessBeforeInitialization' and postProcessAfterInitialization`, methods used to customize instantiation/dependency-resolution before/after spring initialization.
FactoryBean<T> - enforces the implementing class to implement T getObject(), method to invoke while creating an object T, which the implementing class is suppose to produce in factory pattern. boolean isSingleton() can be implemented to specify if this factory returns singleton instance or not (Default true).
Aspects enable the modularization of concerns that cut across multiple types and objects, eg: transaction management. They are also called as crosscutting concerns. IoC doesn't depend on AoP, so its optional to use.
Aspect modularization of a concern that cuts across multiple classes.
Join point point during the execution of a program, such as the execution of a method or the handling of an exception. In Spring AOP, its always a method execution.
Advice action taken by an aspect at a particular join point. Types: around, before & after.
Pointcut predicate that matches join points. Advice is associated with a pointcut expression and runs at any join point matched by the pointcut.
Introduction declaring additional methods or fields on behalf of a type. Spring AOP lets you introduce new interfaces, and a corresponding implementation to any advised object
Target object an object being advised by one or more aspects also called advised object .
Weaving linking aspects with other application types or objects to create an advised object. This can be done at compile time (using AspectJ), load time, or at runtime. Spring AOP (and other pure Java AOP frameworks) does weaving at runtime.
- Before
- After returning
- After throwing
- After
- Around
Spring boot provides auto starters which help quickly write an application with sensible defaults. most commonly used are
- Web starter.
- Data JPA starter.
- Security starter.
- Thymeleaf starter.
The @SpringBootApplication annotation is equivalent to using @Configuration, @EnableAutoConfiguration, and @ComponentScan with their default attributes.
@ComponentScan scans the specified package(s) for all the spring components. @Component indicates that a class is a spring component.
@EnableAutoConfiguration@SpringBootApplication
Use excludes arg provided by @EnableAutoConfiguration
Generally @Controller is meant for human consumption format eg, HTML.
@RestController is used for machine consumption in JSON/XML format.
Meant to be used for different environment during devlopment, testing and production phases of software developement.
- Instantiate
- Populate properties
- Call setBeanName (BeanNameAware)
- Call setBeanFactory (BeanFactoryAware)
- Call setApplicationContext (ApplicationContextAware)
- PreInitialize (Bean Postprocessors)
- afterPropertiesSet
- Custom Init method
- PostInitialize (Bean Postprocessors) ~~
- destroy (Disposable Beans)
- Custom Destory method
- ApplicationContextAware
- ApplicationEventPublisherAware
- BeanClassLoaderAware
- BeanFactoryAware
- BeanNameAware
- BootstrapContextAware
- LoadTimeWeaverAware
- MessageSourceAware
- NotificationPublisherAware
- PortletConfigAware
- PortletContextAware
- ResourceLoaderAware
- ServletConfigAware
- ServletContextAware full list of aware