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
23
votes
11 answers

Aspect-Oriented Objective-C Library?

Is there any Aspect-Oriented Objective-C library that I could perhaps use for iPhone development?
luvieere
  • 37,065
  • 18
  • 127
  • 179
23
votes
7 answers

Spring AOP (Aspect) Not executing

I ams using Spring 2.5.6, asm 1.5.3, aspectjrt/aspectjweaver 1.6.1, cglib 2.1_3 In my Web based Spring application I have following class: package uk.co.txttools.aspects; @Aspect public class LoggingAspect { @Before("execution(*…
bhavin
  • 337
  • 1
  • 2
  • 9
22
votes
1 answer

Spring AOP - pointcut for every method with an annotation

I am trying to define a pointcut, that would catch every method that is annotated with (i.e.) @CatchThis. This is my own annotation. Moreover, I'd like to have access to the first argument of the method, which will be of Long type. There may be…
emesx
  • 12,555
  • 10
  • 58
  • 91
22
votes
1 answer

AOP in Dotnet core : Dynamic Proxy with Real Proxy in Dotnet core

I am migrating my application from .Net Framework 4.5.1 to Dot Net Core. I was using RealProxy Class for logging user information and parameters on BeforeExecute and AfterExecute ( like this link) Now it seems there is no such a thing in Dot…
Pouya Samie
  • 3,718
  • 1
  • 21
  • 34
22
votes
4 answers

Maven: compile aspectj project containing Java 1.6 source

Primary Question What I want to do is fairly easy. Or so you would think. However, nothing is working properly. Requirement: Using maven, compile Java 1.6 project using AspectJ compiler. Note: Our code cannot compile with javac. That is, it fails…
gMale
  • 17,147
  • 17
  • 91
  • 116
22
votes
3 answers

Spring AOP Pointcut syntax for AND, OR and NOT

I'm having trouble with a pointcut definition in Spring (version 2.5.6). I'm trying to intercept all method calls to a class, except for a given method (someMethod in the example below).
Odinodin
  • 2,147
  • 3
  • 25
  • 43
22
votes
3 answers

Have you used Perf4J to collect and analyze performance metrics in Java app?

Did you use Perf4J in your Java application to collect and analyze performance stats? What was the typical pattern (using log files, utilities, UI, JMX, etc.)? Did you use annotations and AOP-based features? Did you use any JMX integration? How…
topchef
  • 19,091
  • 9
  • 63
  • 102
21
votes
2 answers

What Aspect-Oriented Programming (AOP) libraries for .NET are still actively developed?

I am trying to find a reasonably mature/stable and freely available (preferably open-source) library for doing AOP in .NET. I've been searching around a bit and found the products below; however, most of them seem dead: PostSharp — this is the AOP…
stakx - no longer contributing
  • 83,039
  • 20
  • 168
  • 268
21
votes
5 answers

Spring AOP pointcut for annotated argument

Say I have a method like so: public void method(@CustomAnnotation("value") String argument) Is there a pointcut expression that could select all methods with arguments annotated with @CustomAnnotation? If so is there a way I could get access go…
mogronalol
  • 2,946
  • 8
  • 38
  • 56
20
votes
3 answers

@AspectJ pointcut for methods that override an interface method with an annotation

How can I write an aspectj pointcut that applies to method executions which override an interface method with an annotation? For example: interface A { @MyAnnotation void method(); } class B implements A { void method(); } The pointcut…
Dr. Hans-Peter Störr
  • 25,298
  • 30
  • 102
  • 139
20
votes
1 answer

How to debug Spring AOP

I have a problem with Spring AOP which doesn't ties an aspect to all the methods it should (in my opinion) (see this question for more about the root problem: Spring AOP ignores some methods of Hessian Service). How can I debug, what methods and…
Jens Schauder
  • 77,657
  • 34
  • 181
  • 348
20
votes
9 answers

Aspect does not work with Spring boot application with external jar

I am trying to create a timer aspect for measuring methods run time. I created an annotation named @Timer: @Retention(RetentionPolicy.RUNTIME) @Target(value = {ElementType.METHOD, ElementType.TYPE}) public @interface Timer { String…
Avi
  • 21,182
  • 26
  • 82
  • 121
20
votes
1 answer

Pointcut for annotated methods or methods in annotated classes

I need a pointcut for methods in classes annotated with @X or methods annotated with @X. I also need the annotation object. If both the class and the method are annotated I prefer to get the method annotation as argument. I tried the following,…
ASA
  • 1,911
  • 3
  • 20
  • 37
20
votes
4 answers

Spring AOP Advice on Annotated Controllers

I am trying to use AOP to do some processing after an annotated controller. Everything is running with no errors, but the advice is not being executed. Here is the controller code: @Controller public class HomeController { …
jdana
  • 201
  • 1
  • 2
  • 5
19
votes
4 answers

Spring AOP The matching wildcard is strict, but no declaration can be found for element 'aop:config'

Line 13 in XML document from class path resource [ApplicationContextAOP.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element…
Aubergine
  • 5,862
  • 19
  • 66
  • 110