aspectj

Using Aspectj compile time weaving and Java compile time annotation processing in one project

橙三吉。 提交于 2019-12-24 09:52:48
问题 I have searched far and wide and have not found anything that would help me resolve my problem. I am trying to implement a certain functionality and I am creating a PoC solution, here is the issue though: it involves using both compile time weaved AspectJ and compile time annotation processors and I have no idea how to make both of those work at the same time. So far I have been using just AspectJ aspects in *.aj files with the aspectj-maven-plugin, and it was working fine. As soon as I tried

Get class name and method parameters in the aspect

依然范特西╮ 提交于 2019-12-24 09:28:30
问题 I am working on a project that is basically a lot of processes that run periodically. Each process is a different class that extends an abstract class RunnableProcess we created, which contains the abstract method run with the signature below: public abstract void run(Map processContext) throws IOException; To improve modularization on the project, I'm starting to use Aspect Oriented Programming (AOP) to intercept the run calls from every RunnableProcess . I am still learning AOP, and I have

Cannot override method and cannot access field while using idiom “Providing a default interface implementation”

时光怂恿深爱的人放手 提交于 2019-12-24 08:56:20
问题 Here is code: IDefaultInterface.aj: public interface IDefaultInterface { public void m1(); static aspect Impl{ public int f1; public void IDefaultInterface.m1(){ } } } DefaulstInterfaceClass.java: public class DefaultInterfaceClass implements IDefaultInterface { @Override public void m1() { } void mm() { f1 = 9; } } In the second piece of code I'm trying to override m1() method and access f1 field. The compiler allows neither one. How to overcome these limitations? Additional thoughts. I

aspectj cross-thread pointcut

牧云@^-^@ 提交于 2019-12-24 07:46:55
问题 I am new with AspectJ annotation for Java, and I am wondering if it is possible to put pointcut on a cross thread invocation. Here is the code: public class App { public static void main( String[] args ) { new Connector().getStart("testtest"); } } public class Connector { public void getStart(String s1) { Handler h = new Handler(s1); h.start(); } } public class Handler extends Thread { String s1; public Handler(String s1) { this.s1 = s1; } public void run() { new Plain().getValue(s1); } }

AspectJ with Maven (still) not working

送分小仙女□ 提交于 2019-12-24 07:18:08
问题 I am trying to create a sample maven project with aspectj in Eclipse Neon. However, aspects are not weaving/working (see output below). I tried looking into lots of causes and solutions but none worked (see related questions below). Any help/insights would be very much appreciated. Thanks! Technologies used : Java jdk-1.8 Eclipse (Java EE) Neon 3 Apache Maven 3.5.0 junit-4.5 (included through maven) aspectjrt-1.8.9 (included through maven) (I also installed the AJDT plugin to my Eclipse

Custom Java annotation to skip the method execution

痴心易碎 提交于 2019-12-24 07:05:10
问题 I want to create a custom annotation to skip method execution This is my annotation code, with the validator class @Target({ METHOD , FIELD , PARAMETER } ) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy={MyValidator .class}) public @interface MyAnnotation { String message() default "DEFAULT_FALSE"; Class<?>[] groups() default{}; Class<? extends Payload>[] payload() default{}; } I tried it with validator. This is how my validator looks like public class MyValidator implements

Pointcuts for intercept assignment of annotated fields

早过忘川 提交于 2019-12-24 03:59:14
问题 I'm writing a simple auditing framework which allows me to audit the fields of a class which are annotated with an @Audit annotation. Example of possible annotations class User { @Audit private String phoneNumber; private String name; @Audit public getName(){ return name; }; public setName(String name){ this.name=name; } } So far I was only able to define a simple pointcut that watches calls to setters annotated with the @Audit annotation: @Pointcut("call(* @Audit set*(*))") How does a

Spring AOP Logging Interceptor and JAXB issue

落爺英雄遲暮 提交于 2019-12-24 00:54:19
问题 I am trying to implement logging aspect into my application. This is the first time I am attempting AOP, so please let me know if I am missing something obvious. In order to achieve weaving external jars, I am trying to implement load time weaver. I did specify the load-time-weaver in my application context and mentioned TomcatInstrumentableClassLoader in my context.xml file along with the aop.xml. My application is a Spring MVC REST application and utilizes JAXB content negotiation as well.

Adding micrometer dependency causes weird Spring proxy issue

試著忘記壹切 提交于 2019-12-24 00:39:24
问题 I have a simple Spring Boot application with private @Scheduled method: @SpringBootApplication @EnableScheduling public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } @Scheduled(fixedRate = 1000) private void scheduledTask() { System.out.println("Scheduled task"); } } pom.xml: <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi

AspectJ in Play Framework 2.2.1 (Java)

我的梦境 提交于 2019-12-23 20:45:06
问题 I would like to include AspectJ-Weaving in a Play (2.2.1) project. I only found one answer explaining how to add AspectJ to Play (2.1.1) projects. In version 2.2.1 however the project layout changed and there is no Build.scala anymore. In its place build.sbt files are used in newer projects. Can anyone tell me how to add AspectJ to new Play projects? Update: I tried using AspectJ in a Play 2.1.3 project using the configuration provided in the link above. I did in fact get play to compile and