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

C# and C/C++ integration for profiling

I am trying to do some profiles on some applications regarding low-level efficiency in OO frameworks, namely, instruction counts, cache-miss, TLB misses, and things of the sort. So far I was able to do these kind of measurements in Java mixing the…
nuno
  • 1,771
  • 1
  • 19
  • 48
1
vote
1 answer

Play! Framework with JBoss AOP?

Was anybody succesfull in using Play! together with JBoss AOP? Is it generally possible?
j.bamp
  • 11
  • 3
1
vote
0 answers

Autofac - Is it possible to intercept all registrations with an interceptor?

I have read a past thread which talked about this topic. However, it no longer works. May I know in 2022, is there a way to intercept all registration? e.g. use for AOP logging
mannok
  • 1,712
  • 1
  • 20
  • 30
1
vote
1 answer

Spring authorization at package level; AOP?

we have a spring boot app with a java package that has spring controllers with endpoints for admin-like functionality. right now they all start with the same request mapping. so one way i could do authorization of every endpoint in the package is by…
user2052618
  • 556
  • 2
  • 7
  • 20
1
vote
1 answer

external argument injection to method calls in multiple target classes

I have a number of classes that call say Trace.WriteLine("LogSomethingClassSpecific"), in various methods all over the place. Now I would like some of those classes to make all their Trace calls like this:…
Cel
  • 6,467
  • 8
  • 75
  • 110
1
vote
1 answer

SpringBoot application fails startup when I have Aspect defined on a Bean Method

Working with Springboot 2.7.0. I had a a working application and I made these changes on top of it Aspect Configuration @Configuration @EnableAspectJAutoProxy @ComponentScan public class AspectConfig {} Aspect…
Stubborn
  • 290
  • 2
  • 17
1
vote
1 answer

Spring @Async method called from within the class

I've an spring component which has some methods as @Async. I want to create a private method and run @Async but it won't works because spring doesn't help self invocation from withing the bean... Is there a simple way to allow a specific private…
Rafael Lima
  • 3,079
  • 3
  • 41
  • 105
1
vote
1 answer

AspectJ Load Time Weaving with Spring Transaction Manager and Maven

I'm attempting to enable load time weaving with Spring's transaction manager but without too much luck. Currently I'm just trying to run a simple em.persist() in a @Transactional method but it does not appear to running a transaction as seen…
Andrew
  • 11
  • 1
  • 2
1
vote
0 answers

Write an aspect class for my Dropwizard project?

Trying to write a aspectJ class for my dropwizard project. Below is the class @Aspect public class LoggingAspect { @Around("execution(* javax.servlet.http.HttpServlet.*(..)) *)") public Object log(ProceedingJoinPoint joinPoint) throws Throwable…
Laodao
  • 1,547
  • 3
  • 17
  • 39
1
vote
1 answer

AspectJ non-Spring annotations not intercepting adviced methods

I wanted to use AOP-styled annotations for @Around advice in a non-Spring project. I was able to make up some code, but it's been giving me trouble - instead of seeing the console output as coded in the Advice I can only see the SampleClass method's…
Bartek
  • 13
  • 5
1
vote
1 answer

How can we implement Strategy Pattern using AspectJ

Can I implement Strategy Pattern using AOP. I would like to either 1. Override the default algorithm 2. Or Would like to dynamically select any of the given algorithm. Thanks,
user667022
  • 351
  • 3
  • 13
1
vote
0 answers

Is it possible to make java project that use another library which implements AOP using aspectj mave plugin to use the annotations from the library?

I have java library that I created which implements AOP using AspectJ runtime and AspectJ maven plugin. The AspectJ point cut is getting triggered when I add the annotations to the functions which are defined in the same library itself. I want to…
Ali
  • 11
  • 2
1
vote
1 answer

Using AOP or Annotations to extend a service functionality

I would like to know what is the best way in which I can extend an existing functionality (probably by using AOP or Annotations). The scenario which I am looking for is. We have one service say DisableEmployee which uses an entity Employee which…
1
vote
2 answers

Spring AOP for controller inside package

I am looking for a pointcut expression that might satisfy my needs, I have already figured one out but seems to be having some performance issues, and I believe there should be an easier solution. I have a lot of packages…
COCOLICHE
  • 35
  • 4
1
vote
2 answers

Add @Schedule annotation using AOP in Java EE

I am trying to create schedule event using EJB 3.1 @Schedule annotation. Everything works fine as long as I have the annotation inside my bean. Because I want to be able to change schedule in deploy time without repacking ear I want to add this…