Questions tagged [aspect]

An aspect is a module implemented in an Aspect-Oriented Programming language that contains code for a cross-cutting concern, like logging or security. For questions about the aspect ratio of images, use the aspect-ratio tag.

This tag is for Aspect-Oriented Programming. For questions and answers about the aspect ratio of images, please use the tag.

A feature of a program, like logging, is usually spread throughout a program and is not related to that program's main function. Such a feature is called a cross-cutting concern. The aim of aspect-oriented software development (AOSD) (also called aspect-oriented programming or AOP) is to move a cross-cutting concerns into an aspect. This is called refactoring the code.

In AOSD, aspects are written separately from the main application, which can be written in any standard OOP language. An AOP compiler, like AspectJ, compiles the AOP code and object-oriented programming (OOP) code together in a process called weaving.

AOP is often used to enhance legacy applications or 3rd party libraries when the original source code is not available. It is also used to overcome the main weakness of OOP by collecting the cross-cutting concerns into aspects.

Wikis:

See also:

433 questions
5
votes
1 answer

How to get the value of an annotation parameter for usage in AspectJ?

Consider this method: @Access(rights = GUEST) public void foo() { doSomething(); } This pointcut basically matches if the method has an @Access annotation: pointcut check() : execution(@Access * *(..)); But how can I access the field rights of…
soc
  • 27,983
  • 20
  • 111
  • 215
5
votes
1 answer

Writing an integration test for aspect functionality in Spring

I was wondering what I am doing wrong when testing my aspect functionality. The aspect is working in production (passed testing by QA), but I am trying to get my integration unit test to pass. Here is my code: @Aspect @Component public class…
Jack Charlies
  • 51
  • 1
  • 3
5
votes
2 answers

Can AspectJ weave through sun.net.* packages?

I'm using AspectJ to intercept java.net.Socket calls. I've created very simple aspect after(): call(* java.net.Socket.connect(..)) { System.out.println("Connect intercepted!"); } and aop.xml
stackoverflower
  • 3,885
  • 10
  • 47
  • 71
5
votes
1 answer

spring aop that intercepts org.springframework.cache.interceptor.CacheInterceptor#invoke

I have tried the following code , but it does not work: @Component @Aspect @Order(Integer.MAX_VALUE) public class CacheAspect { @Around("execution(public * org.springframework.cache.interceptor.CacheInterceptor.invoke(..))") public Object…
尤慕李
  • 425
  • 6
  • 15
4
votes
1 answer

Aspect call ending before the method is subscribed

I have a method which has reactive code in it (RxJava). I have an Aspect @around wrapped around it. The setup is fine, it does the print out as follows. But it happens before the method is even subscribed to. Is there a way we could set it up such…
Fllappy
  • 371
  • 3
  • 11
4
votes
0 answers

org.aspectj.apache.bcel.classfile.ClassFormatException: File: 'module-info.class': Invalid byte tag in constant pool: 19

I build source by using maven. I find Invalid byte tag in constant pool: 19, and I can not install property. A error cause is a situation that I develop under proxy environment. But I can not understand how to resolve. Could you give me any…
InoueReo
  • 41
  • 1
4
votes
1 answer

Difference between Aspects, concerns and cross-cutting concerns in Spring AOP

Can anyone please explain the difference between Aspects, concerns and cross-cutting concerns in Spring AOP with example? I have gone through a lot of tutorial sites but I didn't get any good explanation.
4
votes
2 answers

Spring Boot @Aspect Logging

I tried to use @Aspect for logging all request and response. If my endpoint has @RequestBody my code is working, but my get endpoints has not @RequestBody and I can't see logs. is that any explanation for this situation? My class like…
Rhmn61
  • 200
  • 2
  • 12
4
votes
1 answer

AspectJ weaving from dependency not applying to project

I have a Java 8 Maven project that defines a custom annotation and an aspect. When running test code in that project itself, it is applying the aspect to the annotated classes. I am then packaging and installing project. I then bring in that…
FiguringThisOut
  • 810
  • 2
  • 9
  • 18
4
votes
2 answers

Spring AspectJ get method annotation from ProceedingJoinPoint

I have an aspect that handles all methods that have a custom annotation. The annotation has an enum parameter and I have to get the value in the aspect: @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface Monitored { …
Evgeni Dimitrov
  • 21,976
  • 33
  • 120
  • 145
4
votes
2 answers

Android aspect No such property: project for class: com.android.build.gradle.LibraryPlugin

I am use aspect, the problem is come out when upgrade gradle from 2.2.3 to 2.3.0 in this line : "-bootclasspath", plugin.project.android.bootClasspath.join( File.pathSeparator)] here is the full build.gradle android.libraryVariants.all…
yefeng
  • 111
  • 1
  • 14
4
votes
1 answer

Can't catch exception from main in: after() throwing(Exception e) - AspectJ

I am trying to catch an exception that is thrown within my main in my Java class. My main's code: public static void main(String[] args){ new something(); throw new RuntimeException(); } In my aspect, I have created both after() returning:…
Marialena
  • 817
  • 8
  • 31
4
votes
3 answers

Could not find dependencies for aspectj-maven-plugin

I have a problem with CTW aspects using aspectj-maven-plugin. I get the following error (execution entry is being highlighted): Multiple annotations found at this line: - Execution default of goal…
kboom
  • 2,279
  • 3
  • 28
  • 43
4
votes
1 answer

Synchronized pointcuts in aspectj

I'am building a Rest server with aspectj. For synchronization i want to use aspects. I defined such pointcut to capture all the points where update and delete events happen: I defined an annotation and use the annotation to capture methods to…
pisuvar
  • 257
  • 1
  • 6
  • 19
4
votes
1 answer

Can I debug in Intellij Idea over @Around aspect

I have a couple of @After and @Before aspects, and debug is working just fine. But when I try with @Around, it just wont stop at the break point. I have logs, and I'm sure that aspect code is executed. Is this normal, or is it just me? Thanks in…
Djordje Ivanovic
  • 4,151
  • 4
  • 27
  • 49
1
2
3
28 29