Spring
What's Spring?
Spring is a modular POJO framework that provides hundred of packages for supporting Web and enterprise application development.
At its core, Spring is a container that can manage the entire life cycle of an application.
The container implements the IoC pattern that allows us to keep the dependences between different objects dynamic.
Q: What's a dynamic dependence?A: For example, an object can have a reference to another object or to external resource like mail server.
IoC container
The Spring IoC container supports two types of DI:
- constructor injection
- setter injection
To manage all the dependencies between objects the IoC uses:
- external XML configuration file
- annotations
- Spring Bean?
- It is any kind of object managed by the Spring container, it is called bean.
- Java Bean (JB)?
- An JB is a reusable general-purpose Java software component. It is a simple POJO Java Object that is serializable, has a nullary constructor, and allows access to properties using getter and setter methods. JBs can be visually manipulated in a builder tool.
- Java Beans are used to encapsulate many objects into a single object (the bean), so that they can be passed around as a single bean object instead of as multiple individual objects.
- A Java Bean is little more than a bag of data, containing state but not behaviour.
- Enterprise Java Beans (EJB)?
- An EJB is a reusable server-side enterprise software component which need to execute in an EJB container.
How to start a spring project
-
In Maven POM.xml import the sprign-context.jar module
Maven will download the spring-context.jar library and its dependencies.
-
Add Spring Project Nature to tell the Eclipse IDE to let us use some of the IDE functionalities provided by the Eclipse plug-ins.
Spring Architecture
The Spring architecture is divided into different modules.
Upper modules dependent on the lower modules
Spring Modules and Maven Dependences
- Spring Core
- The basic IoC container for the objects (beans);
-
org.springframework spring-core 2.5.6 org.springframework spring-agent 2.5.6 - AOP
- provide apect Oriented Programming functionalities. Spring is integrated with the AspectJ framework. It helps in removing many scalability problems and modularizes the application
-
org.springframework spring-aop ${spring.version} org.springframework spring-aspects ${spring.version} - Context
- Extends the core module. It provides the ApplicationContex: an advanced implementation of the bean factory of the IoC container.
-
org.springframework spring-context ${spring.version} - TX
- Transaction management services for the Java objects. They improve the efficiency of the connection, and thus reduce the risk of losing updates or of partial failures.
-
org.springframework spring-tx ${spring.version} - Web (Web MVC, Portlet MVC, Web Framework)
- built on top of the Web Module to provide the capabilities to use the standard MVC design pattern in the Web application view, as well as the service to implement other frameworks such as GWT
- Enterprise framework integration:
- not just an IoC container but a JEE application framework as well. It includes support for popular enterprise Java frameworks such as JMS, E-MAIL, and EJB.
- JDB:
- built on top of the native Java JDBC APIs, improving exception handling, query execution, and configuration, while still providing full access to the native JDBC.
- ORM
- provide integration support for the most popular Java ORM frameworks.
-
com.google.appengine.orm datanucleus-appengine 1.0.7.final com.google.appengine appengine-api-1.0-sdk ${gae.version} com.google.appengine appengine-testing ${gae-test.version} test com.google.appengine appengine-api-stubs ${gae-test.version} test com.google.appengine appengine-api-labs ${gae-test.version} test javax.persistence persistence-api 1.0 org.datanucleus datanucleus-core ${datanucleus.version} runtime javax.transaction transaction-api org.datanucleus datanucleus-jpa 1.1.5 org.datanucleus datanucleus-rdbms ${datanucleus.version} org.datanucleus datanucleus-enhancer 1.1.4 javax.jdo jdo2-api 2.3-ec javax.transaction transaction-api org.hibernate hibernate-validator 4.1.0.Final javax.xml.bind jaxb-api com.sun.xml.bind jaxb-impl - TESTING
- Crating unit and integration tests.
-
org.springframework spring-mock 2.0-rc3 org.springframework spring-test 2.5.6 junit junit 4.8.1 test log4j log4j 1.2.16