Spring’s primary features are dependency injection (DI) and aspect-oriented programming (AOP).
For simplify Java development, spring employs four key strategies:
1. Lightweight and minimally invasive development with plain old Java objects (POJOs).
2. Loose coupling through DI and interface orientation.
3. Declarative programming through aspects and common conventions.
4. Eliminating bolierplate code with aspects and templates.
Dependency injection
Coupling is a two-headed beast, on the one hand, tightly coupled code is difficult to test, difficult to resure and difficult to understand, on the other hand, coupling is necessary – in order to do anything useful, classes need to know about each other somehow.
With DI, objects are given their dependencies at creation time by some third party that coordinates each objects in the system.
The act of creating associations between aplication components is commonly refered to as wiring.
In a spring application, the spring application context is fully responsible for the creation of and wiring of the objects that make up the application. Spring comes with several implementations of its application context, each primarily differing only in how it loads its configuration.
Aspect-oriented programming
System are composed of several components, each responsible for a specific piece of functionality, but often these components also carry additional reponsibilities beyond their core functionality, such as logging, transaction management or security concern.
With AOP, you can then cover your core application with layers of functionality, these layers can be applied declaratively throughtout your application in a flexible manner without your core application even knowing they exist.
First, you need to declare a bean, then you refer to that bean in the element. Second, you define a pointcut element with an expression attribute set to select where the advice should be applied, the expression syntax is AspectJ’s pointcut expression language.
Template
Many activities require similar boilerplate code, JDBC, JMS, JNDI and the consumption of REST services often involve a lot of commonly repeated code.
Spring seeks to eliminate boilerplate code by encapsulating it in templates.
Spring container
In a Spring application, objects are created, are wried together, and live in the Spring container.
The container is at the core of the Spring framework.
There’s no single Spring container, Spring comes with several container implementations that can be categorized into two distinct type: Bean factories are the simplest containers, providing basic support for DI; Application context build on the nontion of a bean factory by providing application-framework services.
Application context –
XML: ClassPathXMLApplicationContext/FileSystemXMLApplicationContext
Java-Base: AnnotationConfigApplicationContext
Spring bean’s life begin with creation and remain in the application context until the application context is destroyed.
An empty container doesn’t contain anything unless you put something in it.
Spring Modules
For Spring 4.0, these modules can be arranged into six categories of functionality.
Core Spring container
Core/Beans/Context/Expression/Context support
Aspect-oriented programming
AOP/Aspects
Data access & integration
JDBC/ORM/OXM/Transaction/Messaging/JMS
Web and remoting
Web/Web servlet/Web portlet/Websocket
Instrumentation
Instrument/Instrument Tomcat
Testing
Test