The Spring AspectJ loadtime weaving configuration is building and loading server without any errors, but the aspect is not getting invoked.
Here is the list of configuration 1) JDK 8 2) Server Jetty
@Configuration
@ComponentScan(basePackages = {..})
@EnableSpringConfigured
@EnableLoadTimeWeaving(aspectjWeaving=AspectJWeaving.ENABLED)
@PropertySource(...)
@ImportResource(value = { "classpath:META-INF/aop.xml", ..})
class config {
...
}
aop.xml
<aspectj>
<weaver options="-Xlint:ignore -Xset:weaveJavaPackages=true -Xset:weaveJavaxPackages=true">
<include within="com.proj.*"/>
<include within="java.*"/>
<include within="javax.*"/>
<include within="org.springframework.*"/>
<include within="org.aspectj.*"/>
</weaver>
<aspects>
<aspect name="com.proj.SampleAspect"/>
</aspects>
</aspectj>
Have also tried with options in aop.xml
options="-XnoInline -verbose -showWeaveInfo -debug -Xlint:ignore -Xset:weaveJavaPackages=true -Xset:weaveJavaxPackages=true"
Aspect
@Component
@Aspect
public class SampleAspect {
@Autowired
private RequestContextFilter interceptRequestContext;
@Around("@annotation(ExecuteByContext)")
public Object interceptByContext(final ProceedingJoinPoint pjp) throws Throwable {
if(SampleUtil.applyForRequest(interceptRequestContext.getRequestContext()) {
LOGGER.info(String.format("Intercept context for method %s", pjp.getSignature().getName()));
return null;
}
return pjp.proceed();
}
}
Annotation
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface ExecuteByContext {
}
@Component
@Configurable
class TestClass implements ISomeInterface{
...
@ExecuteByContext
public void method() {
..
}
@ExecuteByContext
private void method1() {
..
}
}
Jetty server is started with MAVEN_OPTS setting
-javaagent:/path_to/.m2/repository/org/springframework/spring-instrument/4.2.0.RELEASE/spring-instrument-4.2.0.RELEASE.jar
I have the following dependency in my maven
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>4.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-instrument</artifactId>
</dependency>
The SampleAspect is not getting invoked. I have couple of methods (public, private and protected) annotated with @ExecuteByContext.