0

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.

papagei9
  • 41
  • 5
  • I've noticed, that a similar Aspect class (see https://stackoverflow.com/questions/32228031/access-to-session-using-spring-jpa-and-hibernate-in-order-to-enable-filters/32230857#32230857) works out of the box with the default run configuration. I cannot imagine why .. but it somehow fixes the problem, since it also adds a filter param to hibernate. – papagei9 Feb 23 '22 at 14:17
  • Welcome to SO. Please learn how to ask good questions, especially what an [MCVE](https://stackoverflow.com/help/mcve) is. Questions like this one mostly attract close votes, which is certainly not what you want. Make your problem reproducible! Nobody can debug prose. One easy way is to share a GitHub repository with an example project. – kriegaex Feb 25 '22 at 07:45

0 Answers0