Reporter: Brian
Aspect Oriented Programming
Used to decouple the cross-cutting-concerns from the object
Inversion of Control
Dependency Injection is one kind of IoC
classes in a project should be as independent as possible to make the code reusable and testable
DI is used to glue the code to make them cooperate with each other while keeping them independent
DI exists in two major variants
Constructor-based DI
Setter-based DI
Ioc Container
Spring BeanFactory Container
The most commonly used BeanFactory implementation is the XmlBeanFactoryclass
Reads the configuration metadata from an XML file and uses it to create a fully configured system or application.
Preferred where the resources are limited like mobile devices or applet based applications.
Spring ApplicationContext Container
The ApplicationContext container includes all functionality of the BeanFactory container, so it is generally recommended over the BeanFactory.
FileSystemXmlApplicationContext
ClassPathXmlApplicationContext
WebXmlApplicationContext
Decoupled from the format in which this configuration metadata is actually written.
three important methods to provide configuration metadata to the Spring Container
XML based configuration file.
Annotation-based configuration
Java-based configuration
Beans
The most basic unit in Spring, they work together to reach a common goal
Set up the configurations in the container to tell it what beans should contain & how to wire them together so as to coorparate
A bean is an object that is instantiated, assembled, and otherwise managed by a Spring IoC container.
configuration metadata
How to create a bean
Bean's life cycle
Bean's scope
Bean Definition(Attributes)
class
specify the bean class to be used to create the bean.
name
specifies the bean identifier uniquely.
scope
specifies the scope of the objects
singleton(Default)
Spring will return the same bean instance each time one is needed
prototype
Force Spring to produce a new bean instance each time one is needed
request
This scopes a bean definition to an HTTP request.
session
This scopes a bean definition to an HTTP session.
global-session
This scopes a bean definition to a global HTTP session.
constructor-arg
used to inject the dependencies
properties
used to inject the dependencies
autowiring mode
used to inject the dependencies
lazy-initialization mode
ells the IoC container to create a bean instance when it is first requested, rather than at startup.
initialization method
A callback to be called just after all necessary properties on the bean have been set by the container.
destruction method
A callback to be used when the container containing the bean is destroyed
BeanPostProcessor
defines callback methods that you can implement to provide your own instantiation logic, dependency-resolution logic etc.
Bean Definition Inheritance
Autowiring modes
no
byName
byType
constructor
autodetect
Annotation based configuration
@Required
The @Required annotation applies to bean property setter methods.
@Autowired
can apply to bean property setter methods, non-setter methods, constructor and properties.
@Autowired on Setter Methods
@Autowired on Properties
@Autowired on Constructors
@Autowired with (required=false) option
@Qualifier
The @Qualifier annotation along with @Autowired can be used to remove the confusion by specifiying which exact bean will be wired.
@Resource
Spring Java Based Configuration
@Configuration
@Bean
@Import
Spring XML Based Configuration
Event Handling
ApplicationContext
core of Spring
manages complete life cycle of the beans
Standard Events
ContextRefreshedEvent
ContextStartedEvent
ContextStoppedEvent
ContextClosedEvent
RequestHandledEvent
Spring JDBC Framework
Spring Transaction Management
Local transaction
global transactions
Key properties
Atomicity:
Consistency
Isolation
Durability
two types of transaction management
Programmatic
Declarative