aspectj

AspectJ: How to get accessed field's value in a get() pointcut

孤人 提交于 2019-12-04 12:48:36
I am writing an aspect logger to write a log whenever any member variable in a given class is accessed. If I write a specific pointcut for a single variable like below, I am able to get the value of the field. @Pointcut("get(* abc.ThreadPoolService.drMaxTh)") public void drFields() {} @AfterReturning(pointcut="drFields()", returning="drMaxTh") public void afterAccessingdrFields(int drMaxTh) { LOGGER.info("Accessed the field drMaxTh " + drMaxTh); } But my class has a dozen+ variables, and I don't intend on writing specific pointcuts for each of them. So, I want to write something like..

@Around @Aspect in the same package only works with @DependsOn

房东的猫 提交于 2019-12-04 12:45:11
Please see the updates below. I have a Spring Boot application where I accept TCP/IP connections: public MyClass implements InitializingBean { @Override public void afterPropertiesSet() throws Exception { try (ServerSocket serverSocket = new ServerSocket(port)) { while (true) { Socket socket = serverSocket.accept(); new ServerThread(socket).start(); } } } ... private class ServerThread extends Thread { @Override public void run() { try (InputStream input = socket.getInputStream(); OutputStream output = socket.getOutputStream()) { // Read line from input and call a method from service: service

How to create an aspect on an Interface Method that extends from A “Super” Interface

萝らか妹 提交于 2019-12-04 12:17:43
问题 I have a service-layer Interface that extends from a base Interface; I would like to create a Pointcut around my service-layer Interface, but on one of the methods defined in the base Interface. For instance.... I have a method in my base Interface called "save()", I put it in my base Interface since just all of my "child" Interfaces will provide "save" functionality. I would like to create a PointCut on only one of my "child" interfaces for when my "save" gets called. I created the pointcut

How does AspectJ's load-time-weaver find META-INF\\aop.xml?

吃可爱长大的小学妹 提交于 2019-12-04 11:25:10
I am attempting to use load-time-weaving to tie perf4j into a program, but it does not seem to be finding aop.xml in my classpath. Either that or it is not weaving the aspect because it is not finding it. I have enabled verbose output from aop.xml but I am not seeing any weaving messages, errors or otherwise. Where does aspectJweaver look for the META-INF/aop.xml? How can I tell which one it is looking for? I have attempted to use a direct path to import the xml with this, but it hasn't worked. -Dorg.aspectj.weaver.loadtime.configuration=C:\dev\trunk\bin\META-INF\aop.xml Note: The program

How to override ant task stored in ant lib directory

喜欢而已 提交于 2019-12-04 10:15:49
At my work we use AspectJ in some of our Java projects. To get this to work with ant builds we have been placing aspectjtools.jar within ant/lib/. I am now working on a particular Java project and need to use a newer version of aspectJ. I don't want to have to get everyone who uses the project to update their local copy of aspectjtools.jar. Instead, I tried adding the newer aspectjtools.jar to the lib directory of the project and adding the following line to build.xml. <taskdef resource="org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties" classpath="./lib/aspectjtools.jar" /> However,

AspectJ compiler (ajc) vs load-time weaving

倖福魔咒の 提交于 2019-12-04 09:28:50
问题 Several questions here: Does ajc change all the classes it compiles (even non-aspect ones)? What if I comiple only aspect classes ant then put them in the same classpath with the common ones? Does the ajc-compiled project perform faster then the one that uses load-time weaving? What if I need to write a library, that does tracing with AspectJ, and then I want this library to work with ANY project? Is load-time weaving the only option in this case? 回答1: ajc (compile time) will only change

AspectJ + Gradle configuration

泪湿孤枕 提交于 2019-12-04 09:25:23
问题 I'd like to use AspectJ in Gradle project (it's not an Android project - just a simple Java app). Here is how my build.gradle looks like: apply plugin: 'java' buildscript { repositories { maven { url "https://maven.eveoh.nl/content/repositories/releases" } } dependencies { classpath "nl.eveoh:gradle-aspectj:1.6" } } repositories { mavenCentral() } project.ext { aspectjVersion = "1.8.2" } apply plugin: 'aspectj' dependencies { //aspectj dependencies aspectpath "org.aspectj:aspectjtools:$

AspectJ Inner-Class Join points

流过昼夜 提交于 2019-12-04 08:40:57
I wonder is there a way to reach the code using aspect in "//do something" part? Thanks in advance. Turan. public class Test { private class InnerTest { public InnerTest() { JButton j = new JButton("button"); j.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { //do something } }); } } } You can use the within or withincode pointcuts to match the containing class, and the cflow pointcut to match the execution of the addActionListener() method, then combine that with an execute pointcut to match the body of the actionPerformed() method. For example this

Reading annotation property in aspect

纵饮孤独 提交于 2019-12-04 08:10:44
How to read annotation property value in aspect? I want my Around advice to be executed for all joint points annotated with @Transactional(readonly=false) . @Around("execution(* com.mycompany.services.*.*(..)) " + "&& @annotation(org.springframework.transaction.annotation.Transactional)") public Object myMethod(ProceedingJoinPoint pjp) throws Throwable { } You can do it without manual processing of signature, this way ( argNames is used to keep argument names when compiled without debug information): @Around( value = "execution(* com.mycompany.services.*.*(..)) && @annotation(tx)", argNames =

How to configure AspectJ with Load Time Weaving without Interface

天大地大妈咪最大 提交于 2019-12-04 07:48:39
问题 On my project, I currently use AspectJ (not just Spring AOP due to some limitation) with the weaving at the Compile Time. In order to speed up the development on Eclipse, I want to do the weaving at the Load Time. I succeed to do that but with one major constraint: using an interface for my service that contained some transactional methods. If I declare the service with its implementation instead of its interface, in the caller class, there is no weaving and so no transaction supported. So if