DEV Community

Cover image for Spring Framework Architecture and Runtime Components
Hamdamboy
Hamdamboy

Posted on

5 1

Spring Framework Architecture and Runtime Components

The mainly concentrated in this post on the Java/ Spring Framework, we are going to study the important modules of the Spring Framework.
Indeed, briefly inform about Spring Framework Architecture and Runtime components differences, and than implementation source codes.

| More source code in the git, you can use freely open source.

Spring Framework Architecure and Spring Framework Runtime (Figure-1).
Alt Text

Let's defining each components in the Figure-1.

Aspect-Oriented Programming

  • Aspect Oriented Programming(AOP) is the important part of the Spring Framework. The Aspect-Oriented Programming used for separating cross-cutting concerns (for example logging, security etc.) from the business logic of the application.

Model-View-Controller (MVC)

  • It an HTTP and servlet-based framework, this provides customization for web applications.

Transaction Management

  • TM is used to unify several transaction management APIs and to coordinate transactions for Java objects.

Core container

  • The core container is the heart of Spring framework and all other modules are built on top of it. It provides the dependency injection feature, also is known as inversion of control. This module contains the BeanFactory (an implementation of factory pattern) which creates and manages the life cycle of the various application objects (known as beans) defined in the Spring bean configuration file.

Application context

  • This module provides various enterprise level services, scheduling, JNDI access, email etc.

Spring DAO

  • Almost every enterprise application needs to interact with the database. Spring DAO module makes it easy to interact with database by providing an abstraction over low level JDBC tasks like creating a database connection, release it etc.

    TodoRepository.java
    
      @Repository
       public interface TodosRepository extends CrudRepository<Todo, Integer> { }
    

    Alt Text

ORM

  • There exist a number of popular object-relational mapping tools like Hibernate, iBatis, JPA etc. Spring ORM module helps in integrating with these tools.
    ToDoService.java


          @Service
          @Transactional
          public class TodoService {
          private final TodosRepository todosRepository;
          public TodoService(TodosRepository todosRepository) {
            this.todosRepository = todosRepository;
          }
        public List<Todo> findAll(){
        List<Todo> todos = new ArrayList<>();
        for(Todo todo : todosRepository.findAll()) {
            todos.add(todo);
         }
          return todos;
        }
    
        public void save(Todo todo){
        todosRepository.save(todo);
      }
    
        public void delete(int id) {
          Optional<Todo> todo = todosRepository.findById(id);
          todosRepository.delete(todo.get());
        }
    
         public Optional<Todo> findTodo(int id){
           return todosRepository.findById(id);
         }
      }
    

Inversion of Control (IoC) or Dependency Injection (DI)

  • A typical java based enterprise application consists of a number of java classes. To accomplish its designated functionality, each java class (A.java) may depend on one or more other java classes. These other java classes are known as dependencies of the java class A. Generally, each class takes the responsibility to obtain the references of the classes it depends upon. This leads to highly coupled application.

  • Spring framework helps in developing the loosely coupled applications by delegating the responsibility of acquiring the dependencies of a java class to the Spring container and allowing the java class to focus only on its designated functionality. The Spring container injects the dependencies into the java class as the container is initialized (usually on application start up.)

  • Dependency injection is also known as inversion of control. Instead of java class obtaining their dependencies from the container, it is the container who is injecting the dependencies in the java class. So there is an inversion of control.

References:

  1. https://www.codejava.net/frameworks/spring/understanding-the-core-of-spring-framework
  2. https://docs.spring.io/spring/docs/4.3.x/spring-framework-reference/html/overview.html
  3. https://dzone.com/articles/spring-framework-tutorial-for-beginners-2
  4. https://github.com/Urunov/Spring-DAO-ORM-JEE-Web-AOP-Core-Boot

Sentry blog image

How to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay