Primary features:
– dependency injection (DI)
– aspect-oriented programming (AOP)

Springs fundamental missing is to simplify Java development:
– lightweight development with POJOs
– declarative programming with aspects and common conventions
– loose coupling with DI and interface orientation
– eliminate boilerplate code with aspects and templates

Keywords: POJO, Bean, Dependency Injection, Wiring, Loose coupling, Boilerplate code, Cross-cutting concerns


No need to implement or extend, POJOs (usually) have no indication of using Spring.

2. Dependency Injection

Dependency Injection makes code simpler, easier to understand and test. Object is not anymore responsible for referencing to other objects, dependencies are used for that.

Class is highly coupled to Task:

public SomeClass(){ this.task = new SimpleTask();

Task is injected (constructor injection) = loose coupling:

public SomeClass(Task t){ this.task = t;

It doesn’t matter what kind of task our class gets as long as it implements Task interface.

Wiring = creating associations between application components (commonly via XML or annotations)

XML based configuration (ClassPathXmlApplicationContext):

<bean id="somelass" class="com.something.something.SomeClass"><constructor-arg value="#..."></bean>...

or Java based configuration (AnnotationConfigApplicationContext):

@Configuration public class SomeClass{ @Bean public Task task(){...

Application context loads bean definitions and wires them together.

public static void main(...) throws Exception { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext (...) ...
Applying aspects

AOP enables capturing functionality that is used throughout the application in reusable components. E.g. logging, transactions management, security,… These system services are called cross-cutting concerns, because they cut across multiple components. This introduces two levels of complexity, business logic is separated and objects remain POJOs.
E.g. logging before and after a method execution, see elements:

<aop:config>, <aop:aspect>, <aop:pointcut>, <aop:before>, <aop:after>

Keywords: Advice, Pointcut,

Eliminating boilerplate code

Spring seeks to eliminate boilerplate code with templates. e.g. JdbcTemplate, SimpleJdbcTemplate

jdbcTemplate.queryForObject("select...", new RowMapper<SomeClass>(){ public SomeClass mapRow(ResultSet rs, int rowNum)...)

We configure beans in XML or Java files. In Spring object lives in containers. Container creates them, wires, configures,…
There is no single container, but they can be categorised in two distinct types:
– BeanFactory (often too low-level)
– ApplicationContext (preferred)

Some application contexts:
– AnnotationConfigApplicationContext
– AnnotationConfigWebApplicationContext
– ClassPAthXmlApplicationContext
– FileSystemXmlApplicationContext
– XmlWebApplicationContext

– load application context from XML

ApplicationContext ac = new FileSystemXmlApplicationContext(c:/someXml.xml)

– load application context from Java class

ApplicationContext ac = new AnnotationConfigApplicationContext(com.springIsFun. ... .SomeClass.class)

…now you can retrieve beans with getBean() method

Beans life: you may want to take advantage of the opportunities, during it’s life, to customize how a bean is created.

Spring modules

– Core Container: Manages how the beans are created, configured, managed. All spring modules are build on top of Core Container.
– AOP Module: Serves as the basis for developing our own aspects
– Data Access: Abstracting away boilerplate code. Also, ORM tools e.g. Hibernate, JPA,…
– Web and Remoting: Building web applications where we separate UI logic from the application logic.
– Testing: Collection of mock object implementations for writing unit tests.