-->

Sunday, June 2, 2019

Spring Core Containers and Dependency Injection

Java classes should be as independent as possible from each other.


  • To decouple classes from one another, dependencies should be injected through Constructors and Setters.
  • Classes should not configure themselves. IoC uses dependency injection to: 
    • Configure a class correctlyi from outside the class
    • Wire services or components.
  • Piecing together all the beans in the Spring Container is called Wiring.
    • This can most commonly be don through xml.
    • Various BeanFactories and ApplicationContext objects that support wiring include:
      • XMLBeanFactory
      • ClassPathXMLApplicationContext
      • FileSystemXMLApplicationContext
      • XMLWebApplicationContext

Spring Fundamentals

Originally developed to fight against low level maintenance, Spring framework functionality can be used in any JavaEE server and most of it is also adaptable to non-manage frameworks.

Most JavaEE applications are complex and require a lot of effort to develop.

Spring's BeanFactory enables configuration options from XML by providing dependencies when required, automatically.

Spring is composed of 7 key components. These modules can be chosen freely as needed.

  1. Spring Coreseparates configuration from dependencies
    • Prime Components: BeanFactory; Application contexts.
    • Bean Factory: Provides support for dependency injection.
    • Application Contexts: provides application framework services.
  2. Spring Context
    • A configuration file that provides contextual information to the Spring Framework. JNDI, EJB, email, scheduling and internalization services.
  3. Spring AOP
    • Integrates Aspect Oriented Programming through its configuration management feature, providing transaction management services for objects in any Spring-based application.
  4. Spring DAO
    • Data Access Object abstraction layer offers a meaningful hierarchy for the managing of exceptions and error messages. This greatly reduces the amount of code you need to write, such as opening and closing connections.
  5. Spring ORM
    • Object Relational Map -Object oriented programs and relational databases tend to speak completely different languages. This bridges that gap. This provides support to several ORM solutions, including Hibernate, JDO, JPA, and others.
  6. Spring Web Module
    • Builds on top of the application context module, to provide contexts for Web-based applications. The Web module
  7. Spring MVC
    • A full featured MVC implementation for building Web-applications. Highly configurable via strategy interfaces. It accommodates numerous view technologies including JSP, Velocity, Tile, and so on.