aspectj

Gradle and AspectJ - avoid weaving my own packages during compile time

半城伤御伤魂 提交于 2019-12-11 11:29:55
问题 I'm creating an aspectj project, which is NOT spring related. All the aspects were written by me. So Far I've been working with "ant" build to compile my agent, and now I'm trying to move to gradle. My problem - I don't want my classes to be instrumented, but the ajc weaves my code as well, so if I'm adding a point cut to "someFunction()" function and my code com.myproject.MyClass has a function called "someFunction" it will be instrumented. How can I configure the gradle aspectj plugin to

Why my Aspect doesn't do anything?

我只是一个虾纸丫 提交于 2019-12-11 10:48:15
问题 This is a simple class which is an aspect: package aspectTest; import java.awt.Color; import javax.swing.JLabel; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Pointcut; @Aspect public class aspect { @Pointcut("execution(static String createMultiLabel(..))") public void multilabelCreation() {} @Around("multilabelCreation()") public String changeLabelColours

Spring autowired bean for @Aspect aspect is null

こ雲淡風輕ζ 提交于 2019-12-11 10:44:17
问题 I have the following spring configuration: <context:component-scan base-package="uk.co.mysite.googlecontactsync.aop"/> <bean name="simpleEmailSender" class="uk.co.mysite.util.email.simple.SimpleEmailSenderImplementation"/> <aop:aspectj-autoproxy/> Then I have an aspect: @Aspect public class SyncLoggingAspect { @Autowired private SimpleEmailSender simpleEmailSender @AfterReturning(value="execution(* uk.co.mysite.datasync.polling.Poller+.doPoll())", returning="pusher") public void afterPoll

Executing PointCut depending on Environment variable or property

若如初见. 提交于 2019-12-11 10:36:04
问题 I've developed a nice Spring Aspect which I can use to monitor my service operations performance. If some operations are taking a long time to execute, it logs them. @Aspect public class PerformanceMonitorAspect { private Logger logger = LoggerFactory.getLogger("performance"); @Pointcut("execution(* com.company.MyService+.*(..))") public void pointCut(){ } @Around("pointCut()") public Object profileServiceMethods(ProceedingJoinPoint thisJoinPoint) throws Throwable { MethodSignature ms =

Wrap a spring aspects with another aspect

陌路散爱 提交于 2019-12-11 08:54:43
问题 I've declared two aspects as foo & bar over a function runFunc and I want to capture time taken to run the function runcFunc & Bar in Foo , but it is capturing the time only for runFunc . Bar is running independently. I want that If I put two annotation over a function, the 1st annotation should wrap the 2nd annotation and the 2nd one should wrap the function runfunc . How can I achieve that? 回答1: It turns out aspect can wrap other aspects just as easily as they can wrap a function. Following

AspectJ: add static initializer to class

早过忘川 提交于 2019-12-11 08:53:14
问题 Some of my Java classes have static methods marked with a special annotation, @Assert , containing sanity checks. I'd like to perform these checks before any code gets actually executed. The best would be to call these methods from <clinit> . How to get similar behavior using AspectJ, and without modifying initial code? 回答1: AspectJ provides a staticinitialization(TypePattern) pointcut definition that will select existing static initializers and intercept them. Doesn't appear to be able to

Surefire way of checking whether aspectJ mode is working for spring transaction management

China☆狼群 提交于 2019-12-11 07:34:42
问题 I am working on a spring boot application. I have tried to enable AspectJ mode for transaction management as follows: @EnableTransactionManagement(mode = AdviceMode.ASPECTJ) I am suspecting the aspectJ mode is not working and I would like to know whether or not AspectJ mode is indeed enabled for my application. Can someone please provide a way to check that (e.g. through enabling a logger or debugging)? 来源: https://stackoverflow.com/questions/44115996/surefire-way-of-checking-whether-aspectj

AspectJ pointcut on method in Spring CrudRepository

两盒软妹~` 提交于 2019-12-11 07:13:11
问题 I'm using Spring's CrudRepository in combination with the annotation @RepositoryRestResource to implement a simple CRUD-app that can be used throught a RESTful API. I now want to add an AspectJ pointcut on my repository , so that some functionalities will be executed whenever a CRUD-method from the interface is called. First, I extend Spring's CrudRepository to add some custom functionalities in my own interface: @RepositoryRestResource(collectionResourceRel = "customers", path = "customers")

AspectJ Plugin Aspect Config with Maven using external Jar for Aspect

点点圈 提交于 2019-12-11 06:35:46
问题 I am using Perf4j to do performance logging. It specifies that you use aop.xml to define which Aspect you want to be called at compile time depending on which logging system you are using. I cannot get it to pick up the aop.xml file which is in src/main/webapp/meta-inf/aop.xml I cannot figure out how to get my Maven plugin to only weave the log4j aspect. <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>aspectj-maven-plugin</artifactId> <version>1.3</version> <configuration>

Pointcut that will capture constructor calls

删除回忆录丶 提交于 2019-12-11 04:38:30
问题 I am trying to define a pointcut which will capture all the constructor calls, regardless of the modifier, return type, or class. I have used the following code after():execution(* * * .new(..)) I am having an error : Syntax error on token "*", "(" expected. Can anybody suggest what may be the right approach? 回答1: Just remove the middle star "*". It does not make sense to specify a return type for a constructor call because it is clear that the constructor will always return an instance of