diff --git a/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/ServiceConnectionContextCustomizerFactory.java b/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/ServiceConnectionContextCustomizerFactory.java index 9e1b86d526..a22c84dfb8 100644 --- a/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/ServiceConnectionContextCustomizerFactory.java +++ b/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/ServiceConnectionContextCustomizerFactory.java @@ -74,8 +74,12 @@ class ServiceConnectionContextCustomizerFactory implements ContextCustomizerFact field.getDeclaringClass().getName(), Container.class.getName())); Class containerType = (Class) fieldValue.getClass(); C container = (C) fieldValue; - return new ContainerConnectionSource<>("test", origin, containerType, container.getDockerImageName(), - annotation, () -> container); + // container.getDockerImageName() fails if there is no running docker environment + // When running tests that doesn't matter, but running AOT processing should be + // possible without a Docker environment + String dockerImageName = isAotProcessingInProgress() ? null : container.getDockerImageName(); + return new ContainerConnectionSource<>("test", origin, containerType, dockerImageName, annotation, + () -> container); } private Object getFieldValue(Field field) { @@ -83,4 +87,8 @@ class ServiceConnectionContextCustomizerFactory implements ContextCustomizerFact return ReflectionUtils.getField(field, null); } + private boolean isAotProcessingInProgress() { + return Boolean.getBoolean("spring.aot.processing"); + } + }