← Back to list

Main Features in Spring (POJO, IoC/DI, AOP, PSA)

Definition of POJO (Plain Old Java Object), IoC (Inversion of Control) / DI (Dependency Injection), AOP (Aspect Oriented Programming), PSA.

leedohyung28 · 2024-11-17 03:28 · 2 claps · 2.9 min read
#plain-old-java-object #inversion-of-control #depedency-injection #aspectorientedprogramming #sap
Open on Medium ↗
Wiki topics: CRY · Crypto & Web3 💻 · Programming

Main Features in Spring (POJO, IoC/DI, AOP, PSA)

Spring

Spring is a Java based Application Framework.

Main Features

Plain Old Java Object (POJO)

A generic Java object without special conventions or requirements is called POJO.

In Spring framework, POJO is used to implement business logic.

public class User {
    private String name;
    private int age;

    public User(String name, int age) {
        this.name = name;
        this.age = age;
    }

    // Getter
    public String getName() {
        return name;
    }

    // Setter
    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}

Inversion of Control (IoC)

IoC is a concept that includes Dependency Injection (DI), which means that the lifecycle and dependencies of an object are managed by the framework.

In other words, control shifts to the way objects are provided externally rather than creating their own.

This has the advantages of “reduced coupling”, “easy to testing”, and “enhancing maintainability”.

Dependency Injection (DI)

DI is a specific implementaion of IoC that externally injeects dependencies between objects.

Constructor Injection

Passing objects that need dependencies as parameters to the constructor, which is recommended by Spring.

  • Immutability (can be declared final )
  • Easy to test
  • Prevents circular references
  • Code can be complex
@Service
public class UserService {
    private final UserRepository userRepository;

    // @Autowired (Can be Omitted)
    public UserService(UserRepository userRepository) {
        this.userRepository = userRepository;
    }
}

Setter Injection

Injecting dependencies through ‘setter’ methods

  • Flexibility
  • Solves Circular Dependencies
  • Dependency Injection ordering issues
public class UserService {
    private UserRepository userRepository;

    public void setUserRepository(UserRepository userRepository) {
        this.userRepository = userRepository;
    }
}

Field Injection

Injecting directly into fields with annotation @Autowired in Spring.

  • Easy to use
  • Hard to test
  • No Immutability
@Service
public class UserService {
    @Autowired
    private UserRepository userRepository;
}

Aspect-Oriented Programming (AOP)

AOP is the modularization of common concerns to reduce duplication of code. It is a programming paradigm that separates different functinos based on perspective.

Key words

  • Aspect : A modularized unit of common interest.
  • Join Point : The Point at which an ‘Aspect’ can be applied.
  • Pointcut : An expression that specifies a specific ‘Join Point’.
  • Advice : Code executed at the ‘Join Point’ specified by ‘Pointcut’. (Before, After, Around)
  • Weaving : The process of combining ‘Aspect’ with business logic. (Runs at runtime, loadtime, and compile-time)

Features of AOP in Spring

  • Proxy-based : AOP in Spring mainly uses JDK dynamic proxy or GCLIB to create proxy objects, which can be used to control access and add additional functionality.
  • Integrating with Spring Containers : It is easy to integrates with IoC containers in Spring and can be used with DI.
  • XML or Annotation based configuration : AOP settings can be defined via XML files or Annotations.

Applying AOP in Spring Framework

  • Transaction Management : Using Spring AOP to wrap method execution so transactions are automatically started and terminated.
  • Logging : Log automatically before and after the execution of a method with the Logging Aspect.
  • Security Check : Prevent unauthorized user access by applying Aspect to check the user’s authentication status before method execution.

Dependency

In order to use AOP, you need to add the following dependencies.

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-aop</artifactId>
</dependency>

Portable Service Abstraction (PSA)

PSA is an absyraction structure that provides a consistent way to access technology regardless of environmental changes.

Providing only the parts of the service that are actually used and not providing unnecessary information.

It is a service abstraction that hides the technology internally through an abstraction layer and helps developers when developing.

Spring Web MVC

@Controller annotation enables handling of @GetMapping and @PostMapping through annotations without overriding methods such as doGet() and doPost() of the HttpServlet class, thankts to the abstraction layer of Spring Web MVC.

Also, if you use <artifactId>spring-boot-starter-webflux</artifactId> as a dependency instead of <artifactId>spring-boot-starter-web</artifactId> , you can run Netty based instead of Tomcat.

The reason why you can do this conveniently with the same code is because of the abstraction layer of Spring.

@Transactional

@Transactional annotation is a guarantee that an in-scope method is transactional.

It provides a convenient abstraction layer for raw transactional operations such as commit and rollback .

You can use different transaction manages like JpaTransactionManager, DatasourceTransactionManager, HibernateTransactionManager, … etc without modifying your code.


메타데이터
post_id
0e4dbed88772
slug
main-features-in-spring-pojo-ioc-di-aop-psa-0e4dbed88772
url
https://medium.com/@dhleee0123/main-features-in-spring-pojo-ioc-di-aop-psa-0e4dbed88772
canonical_url
https://medium.com/@dhleee0123/main-features-in-spring-pojo-ioc-di-aop-psa-0e4dbed88772
author_url
https://medium.com/@dhleee0123
status
ok
fetched_at
2026-08-18 04:47:05