Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions inject/src/main/java/io/avaje/inject/DBeanScopeBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@
import java.util.function.Consumer;
import java.util.function.Supplier;

import jakarta.inject.Provider;
import org.jspecify.annotations.Nullable;

import io.avaje.applog.AppLog;
import io.avaje.config.Configuration;
import io.avaje.inject.spi.AvajeModule;
import io.avaje.inject.spi.Builder;
import io.avaje.inject.spi.ClosePair;
import io.avaje.inject.spi.ConfigPropertyPlugin;
import io.avaje.inject.spi.EnrichBean;
import io.avaje.inject.spi.ModuleOrdering;
import io.avaje.inject.spi.SuppliedBean;
import jakarta.inject.Provider;

/** Build a bean scope with options for shutdown hook and supplying test doubles. */
final class DBeanScopeBuilder implements BeanScopeBuilder.ForTesting {
Expand Down Expand Up @@ -220,16 +221,19 @@ private ConfigPropertyPlugin defaultPropertyPlugin() {
return detectAvajeConfig() ? new DConfigProps() : new DSystemProps();
}

private boolean detectAvajeConfig() {
if (ModuleLayer.boot().findModule("io.avaje.config").isPresent()) {
return true;
}
try {
Class.forName("io.avaje.config.Configuration", false, classLoader);
return true;
} catch (final ClassNotFoundException e) {
return false;
}
private static boolean detectAvajeConfig() {
var modules = ModuleLayer.boot();
return modules
.findModule("io.avaje.inject")
.map(m -> modules.findModule("io.avaje.config").isPresent())
.orElseGet(
() -> {
try {
return Configuration.class != null;
} catch (NoClassDefFoundError e) {
return false;
}
});
}

private void initProfiles() {
Expand Down