I want to configure Spring BOOT to use AspectJ's compile time weaving. The base problem that I face is annotations like @Transactional, @Cacheable are ignored if the annotation function is called from within the same object. I know self autowiring is a fix, but that seems to be a design workaround for me and I am not satisfied with it.
I have tried a gradle plugin from io.freefair(io.freefair.aspectj.post-compile-weaving). Again I have configured Spring boot to use AspectJ by annotating springBootMain by @EnableCaching(mode=AdviceMode.ASPECTJ).
Kindly provide me further steps to configure properly. How should I tell aspect to weave this modules or packages? How to tell Spring AOP to not weave already weaved classes?
I am adding my build.gradle.
buildscript {
repositories {
mavenCentral()
jcenter()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "io.freefair.gradle:aspectj-plugin:3.8.0"
}
}
allprojects {
group 'com.XYZ.PQR'
version '1.0-SNAPSHOT'
}
subprojects {
repositories {
mavenCentral()
jcenter()
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'io.freefair.aspectj.post-compile-weaving'
dependencies {
compileOnly 'org.projectlombok:lombok:1.18.6'
annotationProcessor 'org.projectlombok:lombok:1.18.6'
implementation 'org.springframework.boot:spring-boot-starter-web'
compile group: 'org.springframework', name: 'spring-aspects', version: '5.1.8.RELEASE'
compile group: 'org.aspectj', name: 'aspectjweaver', version: '1.9.4'
compile group: 'org.aspectj', name: 'aspectjrt', version: '1.9.4'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
compile localGroovy()
}
}
Spring BOOT Main
@SpringBootApplication
@EnableCaching(mode = AdviceMode.ASPECTJ)
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
Annotations like @Transactional and @Cacheable are getting igonred if the annotated function is called within the same class. I will like to these annotations to work within same class without self autowiring.