Questions tagged [aop]

AOP stands for Aspect-Oriented Programming. Use this tag if your question is about aspect-oriented concepts and techniques, or for programming problems using AOP extensions in any language. AOP increases modularity by allowing the separation of "cross-cutting concerns" into aspects. Click learn more... to find out what it's all about.

AOP stands for aspect-oriented programming. Questions about aspect-oriented concepts, techniques, and programming problems using AOP extensions in any language should have this tag.

AOP exists because there are two types of requirements in software engineering: functional requirements (concerns) describe specific behaviors; non-functional requirements (cross-cutting concerns) describe general qualities or services. In OOP, concerns are implemented in a very modular way -- all of the code for a concern is kept together, usually in a class. This is a good thing because modular code increases software quality.

However, cross-cutting concerns cannot be modularized in OOP (that's why they're called "cross-cutting" because they 'cut across' the functional concerns). Code for a cross-cutting concern ends up being spread out (tangled) over many, or even all, of the modules in an OOP program. AOP fixes this problem by collecting that spread-out code into one module called an aspect.

Logging, caching, security, and transaction management are examples of cross-cutting concerns. AOP makes it straightforward to retrofit existing applications with any of these services. The original code is not modified. Instead, an aspect is created with advice and pointcuts. Advice is like a class method - it contains code with the new functionality to be added. A pointcut is code that selects one or more join points. Join points are specific places in the existing program where the advice will be applied. The new program is created during a process called weaving, when the original code and the aspect code are integrated with each other. Weaving can be done at compile-time or load-time, so you can add aspects to programs even when you don't have the source code (there are some restrictions, see here for example).

The most widely used AOP language is AspectJ, which is an aspect-oriented enhancement to Java. Using AOP in the Spring framework is also popular here on SO. AOP is accessible in a number of ways including command-line, Eclipse, Spring, and IntelliJ Ultimate. AOP is also available for several other languages: Python, JavaScript, Ruby, Lua, and Smalltalk.

AOP was first used in 1997 at Xerox PARC to solve the problem of tangled cross-cutting concerns in object-oriented programs.

AOP-related SO Tags:

3657 questions
1
vote
0 answers

Junit-integration test for AOP Spring

How can I write Junit test for the following code @Aspect @Component @Slf4j public class SampleAspect { @Value("${timeout:10}") private long timeout; @Around("@annotation(com.packagename.TrackExecutionTime)") public Object…
DKS
  • 9
  • 3
1
vote
1 answer

Integrate Spring AOP as a maven dependency in a spring boot application

Application 1 : (Contains AOP code. A Spring boot application) LogAspect.Java @Aspect @Component public class LogAspect { private final Logger log = LoggerFactory.getLogger(this.getClass()); …
1
vote
1 answer

Is there any way to intercept Angular core methods to do some AOP stuff?

I'm working with Angular 12. I would like to know if it is possible to intercept a core method call such as createComponent() from ViewContainerRef under @angular/core, to be able to do some AOP stuff.
Omar Fendri
  • 119
  • 1
  • 6
1
vote
1 answer

How to make @Around advice (Spring AOP) on RestController GET Method execute after constraint validation in the GET method?

I want constraint validation in the method to happen before around advice aspect execution, but I see the opposite happening. The aspect is triggered without validation. I have the following RestController class: package…
Barani
  • 83
  • 1
  • 8
1
vote
0 answers

A working way to implement Aspect Oriented Programming in Android (either using AspectJ lang or annotations)?

I've recently had some tasks requiring that I need to log an Android app for some events, like adding to cart, checkout, signing in to the app, pressing on a specific button, etc... to Facebook and Firebase platforms. Since these are non-functional…
Ahmad Hamwi
  • 204
  • 2
  • 10
1
vote
1 answer

Spring4D Container Interception a-la Aspect Oriented Programming (AOP)

Goals: In the Delphi programming language. An aspect that intercepts all virtual methods. A class whose constructor requires arguments. A Dependency Injection (DI) container that BOTH Creates an instance of the class, passing the correct arguments…
1
vote
1 answer

Adding AOP to Spring Boot process changes object returned by method to null

I want to add AOP for logging purposes to my Spring Boot application. But it seems to change my application's behavior in unexpected ways. For example, my application has a method, doThis(), which creates a MyObject instance: MyObject myObect =…
Woodchuck
  • 3,869
  • 2
  • 39
  • 70
1
vote
1 answer

Writing an aspectj pointcut for java.io.FileOutputStream

I would like to write a pointcut for the new FileInputstream(File file) constructor. For example, a common way to create a new file in java is: File file = new File(myDirectory, "myFileName.txt"); new FileOutputStream(file); What I've tried so far…
user101
  • 13
  • 3
1
vote
1 answer

Spring ProxyFactoryBean @Autowired not working

I need to intercept methods from a interface, and found this implementation of MethodInterceptor, which I tested on a new spring app and worked. The problem is, I can't seem to get it working on the spring application I need it…
ajms
  • 67
  • 7
1
vote
1 answer

Intercept header & call service before every endpoint

I have a usecase where every single HTTP request to my SpringBoot app will contain an id in a header. I need to call an internal service to retrieve informations stored in my database based on that id; those informations will then be used inside my…
1
vote
1 answer

In spring,Why is throw in ThrowsAdviceInterceptor of type object

Why is the type of throwsAdvice object instead of throwsAdvice? The author's comments reveal that this seems to be an intentional design . I don't know what's the use of this strange looking design, and whether I've ignored any details. public class…
aoyvx
  • 11
  • 1
1
vote
1 answer

Spring-AOP @Inject with Maven not working only in release builds

I'm using Spring-AOP support to inject references via @Inject into objects not managed by the Spring beanfactory. For instance: @Configurable(preConstruction=true) class DefaultContent implements Content { @Inject @Nonnull private Site…
Fabrizio Giudici
  • 532
  • 3
  • 15
1
vote
1 answer

Is it wise to use AppFabric + Postsharp for server side caching

One of my friends wants to use AppFabric caching on server side (WCF services). But to reduce similar functionality across services code, he wants to cache data "automatically" using AOP Postsharp + AppFabric cache. Is it wise to use automatically…
Regfor
  • 8,515
  • 1
  • 38
  • 51
1
vote
2 answers

KafkaListener and __listener @KafKaListener can't resolve 'null' with Aspect Annotation

I'm using @KafkaListener and I need a dynamic topic name so I use the SpEL '__listener' in order to do that @PostConstruct public void init() { myProps= generateTopicDynamically(); } @KafkaListener(topics = "#{__listener.myProps}") public void…
Thibaut
  • 2,596
  • 2
  • 24
  • 24
1
vote
1 answer

Spring AOP not working for model class in spring boot

My aspect class is calling the aspect while startup. but after calling the api mentioned below the model setter methods are not handled through aspect @RestController @AllArgsConstructor @Slf4j public class MyController { @PostMapping("/terms") …
1 2 3
99
100