Skip to content
Discussion options

You must be logged in to vote

Hey! This is actually expected behavior from Quarkus — when you switch between @TestProfiles, Quarkus fully restarts the application and creates a brand new
QuarkusClassLoader. The tricky part is that Java's static final runs once per ClassLoader, not per JVM, so your singleton gets re-created each time. CDI
@ApplicationScoped fails for the same reason.

The easiest fix I've found is using System.setProperty() / System.getProperty() — these live in the JVM itself (not inside the Quarkus ClassLoader), so they survive
restarts:

  public class GlobalSingleton {
      private static final String KEY = "myapp.test.counter";

      public void doStuff() {
          int count = Integer.parseInt(S…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@mensinda
Comment options

@Seongwonp
Comment options

Answer selected by mensinda
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants