So, I have a really weird problem which did cost me hours to find.
I have a simple Spring Boot application which I start with a normal Spring Boot run configuration in IntelliJ.
I've added a special Aspect configuration (see https://callistaenterprise.se/blogg/teknik/2020/09/20/multi-tenancy-with-spring-boot-part2/) which requires two Java Agents (spring-instrument, aspectweaver).
I've added them separately to the run configuration "VM options" as following:
-javaagent:target/dependency/spring-instrument-5.3.8.jar -javaagent:target/dependency/aspectjweaver-1.9.6.jar
They successfully get loaded on start.
Wherever the Aspect function is called, a singleton that has been already used/instantiated before, will magically get reinstantiated and is then of course empty.
This does not happen / works as expected, when I use mvn spring-boot:run
(or just java -jar -javaagent:.... app.jar
) to run the application. In this case, the maven configuration in pom.xml
takes care to add the needed agents.
What I think is that somehow IntelliJ adds special stuff to the run command or something else interferes with the application, so that the Aspect function is not called in the same context/instance.
It should not be related to threads, since it's prepared for it.
Does anybody have an idea, what's happening here? I'd like to keep the Spring Boot run configuration and thus the Debug option, since debugging does not seem to work out of the box with mvn spring-bootn:run
.