Uploaded image for project: 'Debezium'
  1. Debezium
  2. DBZ-9375

Embedded Engine: ClassLoader management for frameworks like SpringBoot

XMLWordPrintable

    • Informational

      When the Embedded Engine is used inside a SpringBoot application that is packed as a nested jar (see https://docs.spring.io/spring-boot/specification/executable-jar/nested-jars.html), the ClassLoader in the submitted thread must be set to the Spring ClassLoader before starting the engine, otherwise the dynamic class loading won't work.

      See a discussion here: https://debezium.zulipchat.com/#narrow/channel/348249-community-postgresql/topic/Unable.20to.20find.20class.20io.2Edebezium.2Econnector.2Epostgresql.2EPostgr/near/535534861

       

      So something like this:

       

      final ClassLoader springClassLoader = Thread.currentThread().getContextClassLoader();
      DebeziumEngine<ChangeEvent<String, String>> engine = createEngine(...);
      executor.submit(() -> {
      final ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
      try {
      Thread.currentThread().setContextClassLoader(springClassLoader);
      engine.run();
      }
      finally {
      Thread.currentThread().setContextClassLoader(originalClassLoader);
      }
      });

              vjuranek@redhat.com Vojtech Juranek
              belizarius007 Radu Dudas (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated:
                Resolved: