How to work with Spring AOP and AspectJ, Aspect, Advice, Pointcut, JoinPoint,
Male avatar

loveprogramming viết ngày 29/04/2021

https://grokonez.com/spring-framework/work-spring-aop-aspectj-aspect-advice-pointcut-joinpoint-annotation-spring-boot

How to work with Spring AOP and AspectJ, Aspect, Advice, Pointcut, JoinPoint, Annotation | Spring Boot

Aspect-Oriented Programming (AOP) helps us cut across many methods, objects and type within the application without embedding it in the business logic. With Spring AOP and AspectJ, you can add additional behaviour to existing code without modifying the code itself.

The tutorial guides you how to work with Spring AOP and AspectJ using Spring Boot.

I. Technology

  • Java 1.8
  • Maven 3.3.9
  • Spring Tool Suite – Version 3.8.1.RELEASE
  • Spring Boot: 1.4.0.RELEASE

    II. Overview

    1. Goal

    To build an application that uses Aspect on 4 services:
  • CustmerAspect on CustomerService: with simple expression
  • CustmerAspectPointcut on CustomerAnotherService: with @Pointcut Annotation and implement Aspect on its own funtions
  • CustmerAdvanceAspect on CustomerAdvanceService: with @Around - most powerful kind of advice, and more usages of JoinPoint for getting argument information
  • CustmerAspectAnnotation on CustomerLoggableService: implement Aspect by creating custom annotation @Loggable

    2. Project Structure

    springaop-aspectj-project-structure

    3. Step to do

  • Create Spring Boot project & add Dependencies
  • Create a DataModel class
  • Create Services
  • Create Aspect Classes and Inferface
  • Create Spring Bean Configuration File
  • Create a Web Controller
  • Run Spring Boot Application & Enjoy Result

    4. Demo Video

    III. Practice

    1. Create Spring Boot project & add Dependencies

  • Open Spring Tool Suite, on Menu, choose File -> New -> Spring Starter Project, then fill each fields: springaop-aspectj-startproject

Click Next, in Web: choose Web:
springaop-aspectj-configweb

Click Finish. Spring Boot project will be created successfully.

  • Open pom.xml, add dependencies for Spring Context, Spring AOP and AspectJ:

https://grokonez.com/spring-framework/work-spring-aop-aspectj-aspect-advice-pointcut-joinpoint-annotation-spring-boot

How to work with Spring AOP and AspectJ, Aspect, Advice, Pointcut, JoinPoint, Annotation | Spring Boot

Bình luận


White
{{ comment.user.name }}
Bỏ hay Hay
{{comment.like_count}}
Male avatar
{{ comment_error }}
Hủy
   

Hiển thị thử

Chỉnh sửa

Male avatar

loveprogramming

451 bài viết.
79 người follow
Kipalog
{{userFollowed ? 'Following' : 'Follow'}}
Cùng một tác giả
Male avatar
1 0
Tutorial Link: (Link) (Ảnh) Django is a Pythonbased free and opensource web framework that follows the modeltemplateview architectural pattern. A...
loveprogramming viết 6 tháng trước
1 0
Male avatar
1 0
https://loizenai.com/angular11nodejspostgresqlcrudexample/ Angular 11 Node.js PostgreSQL Crud Example (Ảnh) Tutorial: “Angular 11 Node.js Postg...
loveprogramming viết 5 tháng trước
1 0
Male avatar
1 0
Angular Spring Boot jwt Authentication Example Github https://loizenai.com/angularspringbootjwt/ (Ảnh) Tutorial: ” Angular Spring Boot jwt Authe...
loveprogramming viết 5 tháng trước
1 0
{{like_count}}

kipalog

{{ comment_count }}

bình luận

{{liked ? "Đã kipalog" : "Kipalog"}}


Male avatar
{{userFollowed ? 'Following' : 'Follow'}}
451 bài viết.
79 người follow

 Đầu mục bài viết

Vẫn còn nữa! x

Kipalog vẫn còn rất nhiều bài viết hay và chủ đề thú vị chờ bạn khám phá!