Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Java Arrays
  • Java Strings
  • Java OOPs
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Java MCQs
  • Spring
  • Spring MVC
  • Spring Boot
  • Hibernate
Open In App
Next Article:
Spring Boot - AOP(Aspect Oriented Programming)
Next article icon

Spring Boot - AOP(Aspect Oriented Programming)

Last Updated : 24 Mar, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

The Java applications are developed in multiple layers, to increase security, separate business logic, persistence logic, etc. A typical Java application has three layers namely they are Web layer, the Business layer, and the Data layer.

  • Web layer: This layer is used to provide the services to the end-user using REST API or the web application.
  • Business layer: All the business logic of the application is written and handled in this layer.
  • Data layer: This layer is used to implement the persistence logic of the application.

Note: The java classes whose instances are stored in database tables are called persistent classes. Data layer used to handle the persistent logic.

AOP(Aspect Oriented Programming)

AOP is a programming paradigm whose main aim is to increase modularity by allowing the separation of cross-cutting concerns. AOP does this by adding additional behavior to the existing code without modifying the code itself. It provides functionalities to add new code and behavior separately.

The AOP provides us the flexibility to define all the common concerns in one class and we can define where all these concerns are used and how they are used in a class without modifying it is existing code and applying the new features. This class with all the cross-cutting concerns is modularized into a specific class call Aspect. In order to use AOP, we need to implement the responsibility of aspect in our class called Advice.

The aspect class provides us the flexibility to:

  1. Define each concern in a single class instead of spreading the concerns all over the codebase.
  2. The business layer only contains the primary logic, all the secondary logic and concerns are placed in a single class, aspect.

There are some key terminologies in Aspect-Oriented Programming that are shown in the tabular manner below as follows:

TerminologiesAction Performed
AspectIt is a module that provides cross-cutting concerns by encapsulating the advice and pointcuts. An application can have any number of aspects in it. In order to use it, we need to annotate a class with @Aspect annotation.
AdviceIt is an action that is taken before or after method execution. An action is a block of code that gets invoked during the execution of a program. The Spring AOP framework support five type of advice before, after, after-returning, after-throwing, and around advice. The advice is taken for join points. Advice is applied over the target object.
PointcutsPointcuts are the set of join points where the advice is executed. These pointcuts are defined using the expression or pattern.
Join PointsIt is a place in an application where the AOP Aspect is applied. A join point can be a method execution, exception handling, etc.
Target ObjectIt is an object where the advice is applied. These target objects are proxied
ProxiedTarget objects are proxied which means during the runtime the target methods are overridden and depending on method configuration, the advice is included in the target object.
WeavingThe process of linking the application with the aspect is called weaving. It can be done at load time, compile time and run time.

Why do we need AOP?

In web applications, each of the layers(web, business, and data layer) are responsible for different tasks and they perform these tasks individually. But there are a few common aspects that are applied to each layer such as security, caching, validation, etc. These common aspects are known as Cross-Cutting Concerns.

Remember: The cross-cutting concerns are implemented at multiple places in an application and they affect the entire application.

The implementation of these cross-cutting concerns in each module separately makes the code lengthy also, makes it difficult to manage. In order to overcome this problem, Aspect-Oriented Programming is introduced. In which, we implement these cross-cutting concerns as an aspect and define pointcuts(set of join points) where these aspects should be applied.


Next Article
Spring Boot - AOP(Aspect Oriented Programming)

A

ankur035
Improve
Article Tags :
  • Java
  • Geeks Premier League
  • Geeks-Premier-League-2022
  • Java-Spring-Boot
Practice Tags :
  • Java

Similar Reads

    Spring Boot – Validation using Hibernate Validator
    Hibernate Validator provides a powerful and flexible way to validate data in Spring Boot applications. Validating user input is essential for building secure and reliable applications. Spring Boot makes this easy with Hibernate Validator, the reference implementation of JSR 380 (Bean Validation API)
    6 min read
    How to Connect MongoDB with Spring Boot?
    In recent times MongoDB has been the most used database in the software industry. It's easy to use and learn This database stands on top of document databases it provides the scalability and flexibility that you want with the querying and indexing that you need. In this, we will explain how we conne
    4 min read
    Spring Boot - File Handling
    Spring Boot is a popular, open-source spring-based framework used to develop robust web applications and microservices. As it is built on top of Spring Framework it not only has all the features of Spring but also includes certain special features such as auto-configuration, health checks, etc. whic
    5 min read
    Spring Boot MockMVC Testing with Example Project
    In a Spring Boot project, we have to test the web layer. For that, we can use MockMVC. In this tutorial, let us see how to do that by having a sample GeekEmployee bean and writing the business logic as well as the test cases for it. Example Project Project Structure:   This is a maven project. Let's
    5 min read
    Spring Boot Integration With MySQL as a Maven Project
    Spring Boot is trending and it is an extension of the spring framework but it reduces the huge configuration settings that need to be set in a spring framework. In terms of dependencies, it reduces a lot and minimized the dependency add-ons. It extends maximum support to all RDBMS databases like MyS
    4 min read
    Spring Boot Integration With MongoDB as a Maven Project
    MongoDB is a NoSQL database and it is getting used in software industries a lot because there is no strict schema like RDBMS that needs to be observed. It is a document-based model and less hassle in the structure of the collection. In this article let us see how it gets used with SpringBoot as a Ma
    4 min read
    Spring Boot MockMVC Example
    Automated testing plays a vital role in the software industry. In this article, let us see how to do the testing using MockMvc for a Spring Boot project. To test the web layer, we need MockMvc and by using @AutoConfigureMockMvc, we can write tests that will get injected. SpringBootApplication is an
    3 min read
    Spring Boot Integration With PostgreSQL as a Maven Project
    PostgreSQL is a user-friendly versatile RDBMS. This article lets us see how to integrate Spring Data JPA with PostgreSQL. There are some conventions to be followed while using PostgreSQL. We will cover that also. Working with PostgreSQL We can easily create databases and tables in that. The below sc
    3 min read
    Spring Boot JPA Sample Maven Project With Query Methods
    In this article, let us see a sample maven project in Spring Boot JPA with Query methods. Spring Boot + JPA removes the boilerplate code and it will be enhanced much if we use query methods as well. Let us discuss this project with MySQL Connectivity for geeksforgeeks database and table name as "Con
    6 min read
    Spring Boot - Service Class Example for Displaying Response Codes and Custom Error Codes
    Sometimes the error or status messages in webpages would be different from the default error message thrown by Tomcat (or any other server). An important reason for this is websites want to look unique in their approach to their users. So, a customized page for displaying status codes is always bett
    6 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences