JavaSpringNotes

This is a personal notes for Java spring framework

Spring introduction#

What is spring#

It is a very popular framework for building Java application and initially a simpler and light weight alternative to J2EE. Also, it provides a large number of helper classes.

Update on Spring 5#

  • Upgraded minimum requirements for Java 8 or higher
  • Deprecated legacy integration for: Tiles, Velocity, portlet, Guava etc
  • Upgraded Spring MVC to use new versions of Servlet API 4.0
  • Added new reactive programming framework: Spring WebFlux

Spring Core Framework#

Goals of Spring#

  • Lightweight development with Java POJOs(Plain-Old-Java-Objects)
  • Dependency injection to promote loose coupling
  • Declarative programming with Aspect-Oriented-Programming(AOP)
  • Minimize boilerplate Java code

Core Container#

Factory for creating beans. Manage bean dependencies.

  • Beans
    • A “Spring Bean” is simply a Java object. When Java objects are created by the Spring Container, then Spring refers to them as “Spring Beans”. Spring Beans are created from normal Java classes …. just like Java objects.
  • Core
  • SpEl
    • Spring extression language
  • Contex

Infrastructure#

Aspect Oriented Programming. Add functionality to objects declaratively.

Logging, security,transactions,etc…

  • Aop
  • Aspects
  • Inplementation
    • Java agents to remotely monitor your app with JMX(Java Management Extension)
  • Messaging

Data Access Layer#

  • JDBC -> helper classes to make easier to access Database
  • ORM -> Object Relational Mapping -> JPA / Hibernate
  • Transactions
  • OXM
  • JMS (Java Message Service)
    • For sending async messages to a Message Broker
    • Spring provides helper classes for JMS

Web Layer#

All Web related classes. Home of the Spring MVC framework.

  • Servlet
  • WebSocket
  • Web
  • Portlet

Test Layer#

Supports Test-Driven-Development(TDD). Mock objects and out-of-container testing

  • Unit
  • Integration
  • Mock

Inversion of Control#

Spring Container#

  • Primary functions
    • Create and manage objects(Inversion of Control)
    • Intect object’s dependencies(Dependency Injection)
  • Configuring Spring Container
    • XML Configuration file
    • Java Annotations
    • Java Source Code
  • Spring container is generically known as Application Context
  • Specialized implementations
    • ClassPathXmlApplicationContext
    • AnnotationConfigApplicationContext
    • GenericWebApplicationContext
    • Others…

Dependency Injection#

The dependency inversion principle.

The client delegates to calls to another object

the responsibility of providign its dependencies

Injection Types#

  • There are many types of injection with Spring
  • We will cover the two most common
    • Constructor Injection
    • Setter Injection
  • Autowiring –> discuss later