Questions tagged [aspectj]

AspectJ is an aspect-oriented extension to the Java programming language that enables clean modularization of crosscutting concerns such as logging, error handling, standards enforcement and feature variations. Use this tag for questions about the programmatic use of this extension. For downloads, support, IDE integration, & documentation, see the "learn more" for this tag.

AspectJ is an Aspect-Oriented Programming (AOP) extension to Java, created by Xerox, that has as main components aspects (consisting of pointcuts and advices) and join points.

For AspectJ Eclipse integration, also see AspectJ Development Tools (AJDT); for NetBeans integration, see AspectJ in NetBeans; for IntelliJ IDEA integration, see IDEA Web Help.

Books:

Documentation:

3304 questions
11
votes
2 answers

Using @Autowired with AspectJ and Springboot

I want to use @Autowired annotation into an "Aspect". I want to inject a repository in my aspect but when I try to call a method of my autowired class a NullPointException occurs. @Aspect public class AspectSecurity { @Autowired private…
maxiplay
  • 427
  • 1
  • 5
  • 13
11
votes
3 answers

How to exclude methods from aspectj

I'm trying to exclude several methods from log files using aspectj (Im usong spring and Load-time weaving). Is there a way to list the excluded methods in the aop.xml? I know i can do this for full classes but I'm looking for specific methods. or…
lior
  • 1,127
  • 3
  • 24
  • 43
11
votes
5 answers

Add code to package private library method

I have a library class with a package private method. Directly overriding this method by a subclass is no option. Is there any way, no matter how ugly, to execute own code when this package private method is called from inside the library, e.g.…
Thomas S.
  • 5,804
  • 5
  • 37
  • 72
11
votes
3 answers

@PreAuthorize does not work with method security rules and method parameters

I am adding Spring Security to one Spring project. The architecture of the system is REST and user can access to different resources. I would like to give access to personal information to administrators and users that are owners of this…
Spacemonkey
  • 1,725
  • 3
  • 20
  • 44
11
votes
2 answers

Modifying parameters in more than one aspect providing around advice

I have two aspects each of which modify method arguments. When both aspects are applied to the same method, I would expect execution of the aspects to be chained and I would expect that the arguments modified in the first aspect to be available to…
Java Junky
  • 131
  • 1
  • 7
11
votes
2 answers

Logging JSON request and response for jersey

I have a JAVA web application application, which exposes RESTful apis. My requirement is to log all the JSON requests and responses that are handled by the server. Is there any parameter like…
Manju Prabhu
  • 454
  • 6
  • 14
10
votes
1 answer

Is it possible to retrieve the object instance performing a method call with AspectJ?

Let's imagine the following aspect: aspect FaultHandler { pointcut services(Server s): target(s) && call(public * *(..)); before(Server s): services(s) { // How to retrieve the calling object instance? if (s.disabled) ...; } …
Jérôme Verstrynge
  • 57,710
  • 92
  • 283
  • 453
10
votes
3 answers

exposing previous value in AspectJ set-pointcut

I have to detect fields value changes. I want to compare the previous value with the new one. I don't know the field name or its type. (More background here.) For sample given class: package…
zacheusz
  • 8,750
  • 3
  • 36
  • 60
10
votes
2 answers

AspectJ - why "advice defined in XYZ has not been applied"?

I just started playing with AspectJ (1.6.11). I'm sending emails via commons-email libary and I'd like to know how long it takes to send a message. So this is my email sending code: import org.apache.commons.mail.Email; import…
batto
  • 171
  • 1
  • 2
  • 10
10
votes
6 answers

Why Spring AOP is not weaving external jars at runtime?

I have a java application build upon Spring 3. This project has another jar as a dependency. This dependency contains a @org.aspectj.lang.annotation.Aspect class (lets say, com.aspectprovider.aspects.MyAspect). There's a @Before advice to weave a…
bluefoot
  • 10,220
  • 11
  • 43
  • 56
10
votes
2 answers

How can I access methods attributes with Spring AOP (AspectJ-style)?

I need to intrecept some methods and their attributes by using annotations as point cuts, but how can I access those method attributes. I have following code that succesfully can run code before method is run, but I just don't know how I can access…
newbie
  • 24,286
  • 80
  • 201
  • 301
10
votes
2 answers

Pointcut matching methods with annotated parameters

I need to create an aspect with a pointcut matching a method if: it is annoted with MyAnnotationForMethod One of its parameters (can have many) is annotated with @MyAnnotationForParam (but can have other annotations as well). The aspect class look…
Patrick Sauts
  • 103
  • 1
  • 1
  • 6
10
votes
4 answers

java.lang.ClassNotFoundException: org.aspectj.util.PartialOrder$PartialComparable

I am using Spring 4.2.4.RELEASE in my web application and I would like to remove the dependency on aspectjweaver.jar from it. I don't use AOP directly and I certainly don't use AspectJ. But my application fails with the following…
Nikem
  • 5,716
  • 3
  • 32
  • 59
10
votes
2 answers

AspectJ: How to weave an aspect library into a Java project

I build small library (Java and Maven) - using AspectJ. Library must be independent. Library deliver Aspects and Annotations. Function of library is - "call advice when executed a method with specific annotation". All is ok when I use everything in…
Patryk Kobus
  • 113
  • 1
  • 7
10
votes
3 answers

Can we enable or disable Aspect based on value of any flag or through configuration file?

I have added following dependency in pom.xml org.springframework spring-aop ${spring.version}
user2758176
  • 193
  • 1
  • 7
  • 20