├── .gitignore ├── README.md ├── pom.xml └── src ├── main ├── java │ └── com │ │ └── example │ │ ├── Interceptor.java │ │ └── InterceptorApplication.java └── resources │ ├── application.properties │ └── org │ └── aspectj │ └── aop.xml └── test └── java └── com └── example └── InterceptorApplicationTests.java /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | dependency-reduced-pom.xml 4 | interpolated-pom.xml 5 | .#* 6 | *# 7 | *~ 8 | build.log 9 | _site/ 10 | 11 | ### STS ### 12 | .apt_generated 13 | .classpath 14 | .factorypath 15 | .project 16 | .settings 17 | .springBeans 18 | 19 | ### IntelliJ IDEA ### 20 | .idea 21 | *.iws 22 | *.iml 23 | *.ipr 24 | 25 | ### NetBeans ### 26 | nbproject/private/ 27 | build/ 28 | nbbuild/ 29 | dist/ 30 | nbdist/ 31 | .nb-gradle/ 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | A simple Spring Boot project to show that AspectJ + Lombok does work with `mvn` but not within IntelliJ: 2 | 3 | # Works 4 | ```bash 5 | $ mvn package -DskipTests && mvn spring-boot:run 6 | ``` 7 | or 8 | ``` 9 | $ mvn package -DskipTests && java -jar target/spring-boot-ctw-0.0.1-SNAPSHOT.jar 10 | ``` 11 | 12 | # Does not work 13 | Run the project from within IntelliJ 14 | ```bash 15 | Error:(18, 0) ajc: log cannot be resolved 16 | ``` 17 | 18 | # Remarks 19 | - Code copied from https://github.com/dsyer/spring-boot-aspectj/tree/master/ctw 20 | 21 | - "Hack" applied from https://palesz.wordpress.com/2011/12/03/howto-maven-lombok-and-aspectj-together 22 | ```xml 23 | true 24 | 25 | 26 | ${project.build.directory}/classes 27 | 28 | ``` 29 | - Related issue: https://youtrack.jetbrains.com/issue/IDEA-184921 30 | 31 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.example 7 | spring-boot-ctw 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | spring-boot-ctw 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.1.1.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 1.0.20.RELEASE 26 | 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-actuator 32 | 33 | 34 | org.springframework 35 | spring-aop 36 | 37 | 38 | org.aspectj 39 | aspectjrt 40 | 41 | 42 | org.springframework.boot 43 | spring-boot-starter-web 44 | 45 | 46 | org.springframework.boot 47 | spring-boot-configuration-processor 48 | true 49 | 50 | 51 | org.projectlombok 52 | lombok 53 | 1.18.4 54 | provided 55 | 56 | 57 | 58 | org.springframework.boot 59 | spring-boot-starter-test 60 | test 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | org.springframework.boot 69 | spring-boot-maven-plugin 70 | 71 | 72 | org.springframework.boot.experimental 73 | spring-boot-thin-layout 74 | ${thin-jar.version} 75 | 76 | 77 | org.aspectj 78 | aspectjweaver 79 | ${aspectj.version} 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | org.springframework.boot 89 | spring-boot-maven-plugin 90 | 91 | 92 | org.codehaus.mojo 93 | aspectj-maven-plugin 94 | 1.10 95 | 96 | ${java.version} 97 | ${java.version} 98 | none 99 | ${java.version} 100 | true 101 | true 102 | 103 | 104 | ${project.build.directory}/classes 105 | 106 | 107 | 108 | 109 | 110 | compile 111 | 112 | 113 | 114 | 115 | 116 | org.aspectj 117 | aspectjtools 118 | ${aspectj.version} 119 | 120 | 121 | org.aspectj 122 | aspectjrt 123 | ${aspectj.version} 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | spring-snapshots 133 | Spring Snapshots 134 | https://repo.spring.io/snapshot 135 | 136 | true 137 | 138 | 139 | 140 | spring-milestones 141 | Spring Milestones 142 | https://repo.spring.io/milestone 143 | 144 | false 145 | 146 | 147 | 148 | 149 | 150 | spring-snapshots 151 | Spring Snapshots 152 | https://repo.spring.io/snapshot 153 | 154 | true 155 | 156 | 157 | 158 | spring-milestones 159 | Spring Milestones 160 | https://repo.spring.io/milestone 161 | 162 | false 163 | 164 | 165 | 166 | 167 | 168 | -------------------------------------------------------------------------------- /src/main/java/com/example/Interceptor.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import org.aspectj.lang.ProceedingJoinPoint; 4 | import org.aspectj.lang.annotation.Around; 5 | import org.aspectj.lang.annotation.Aspect; 6 | 7 | import org.springframework.boot.context.properties.ConfigurationProperties; 8 | import org.springframework.context.event.ContextRefreshedEvent; 9 | import org.springframework.context.event.EventListener; 10 | 11 | @Aspect 12 | @ConfigurationProperties("interceptor") 13 | public class Interceptor { 14 | 15 | /** 16 | * Message to print on startup 17 | */ 18 | private String message = "Started"; 19 | 20 | public String getMessage() { 21 | return message; 22 | } 23 | 24 | public void setMessage(String message) { 25 | this.message = message; 26 | } 27 | 28 | @Around("execution(* *(..)) && !within(com.example.Interceptor)" 29 | + " && (within(org.springframework.context.annotation.Condition+) || within(com.example..*))") 30 | public Object intercept(ProceedingJoinPoint joinPoint) throws Throwable { 31 | Object result = joinPoint.proceed(); 32 | System.err.println(joinPoint.toShortString() + ": " + result); 33 | return result; 34 | } 35 | 36 | @Around("execution(* *(..)) && within(com.example..*) && !within(com.example.Interceptor+)") 37 | public Object stack(ProceedingJoinPoint joinPoint) throws Throwable { 38 | new RuntimeException().printStackTrace(); 39 | return joinPoint.proceed(); 40 | } 41 | 42 | @EventListener 43 | public void started(ContextRefreshedEvent event) { 44 | System.err.println(message + ": " + event); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/example/InterceptorApplication.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.aspectj.lang.Aspects; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.boot.builder.SpringApplicationBuilder; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | @SpringBootApplication 12 | @RestController 13 | @Slf4j 14 | public class InterceptorApplication { 15 | 16 | @RequestMapping("/") 17 | public String home() { 18 | log.info("/ called"); 19 | return "Hello World"; 20 | } 21 | 22 | @Bean 23 | public Interceptor interceptor() { 24 | // This will barf at runtime if the weaver isn't working (probably a 25 | // good thing) 26 | return Aspects.aspectOf(Interceptor.class); 27 | } 28 | 29 | public static void main(String[] args) { 30 | new SpringApplicationBuilder(InterceptorApplication.class).run(args); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.aop.auto=false -------------------------------------------------------------------------------- /src/main/resources/org/aspectj/aop.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/test/java/com/example/InterceptorApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class InterceptorApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | --------------------------------------------------------------------------------