Spring AOP (Aspect-oriented programming) framework is used to modularize cross-cutting concerns in aspects. Put it simple, it’s just an interceptor to intercept some processes, for example, when a method is execute, Spring AOP can hijack the executing method, and add extra functionality before or after the method execution.
In Spring AOP, 4 type of advices are supported :
Launch your preferred IDE (I use STS) and Create New Java Project. And then create the file structure as shown below…
You need to download all the JARs that are in User Libraries “aspectJ-lib” and add them to the project’s class path. You can find these JARs here: Spring, Commons-logging, aspectjrt, aspectjweaver.
package com.dineshonjava.sdnext.aop.tutorial.aspectJ; @Aspect public class LoggingAspect { public void loggingAdvice() { System.out.println("Advice run. Get method is called"); } }
<beans> ..... <bean class="com.dineshonjava.sdnext.aop.tutorial.aspectJ.LoggingAspect" name="loggingAspect"></bean> ..... <aop:aspectj-autoproxy></aop:aspectj-autoproxy> ..... <aop:config> <aop:aspect id="loggingAspect" ref="loggingAspect"> ..... <aop:after method="..." pointcut="..."></aop:after> ..... </aop:aspect> </aop:config> .... </beans>
1. XML Schema based : Aspects are implemented using regular classes along with XML based configuration.
2. @AspectJ based : @AspectJ refers to a style of declaring aspects as regular Java classes annotated with Java 5 annotations.
Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…
Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…
Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…
Technology has emerged a lot in the last decade, and now we have artificial intelligence;…
Managing a database is becoming increasingly complex now due to the vast amount of data…
Overview In this article, we will explore Spring Scheduler how we could use it by…