From 1a2919bb0e58592b0ff16dae22909e2e2237312b Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Tue, 5 Sep 2023 13:37:02 +0200 Subject: [PATCH 1/2] Polish --- .../service/connection/ContainerConnectionSource.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/ContainerConnectionSource.java b/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/ContainerConnectionSource.java index 7ef972e1f7..30aece533d 100644 --- a/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/ContainerConnectionSource.java +++ b/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/ContainerConnectionSource.java @@ -56,7 +56,7 @@ public final class ContainerConnectionSource> implements private final Set> connectionDetailsTypes; - private Supplier containerSupplier; + private final Supplier containerSupplier; ContainerConnectionSource(String beanNameSuffix, Origin origin, Class containerType, String containerImageName, MergedAnnotation annotation, Supplier containerSupplier) { From d310fb6fce1bceed55596cea70186e71eca77655 Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Tue, 5 Sep 2023 13:37:34 +0200 Subject: [PATCH 2/2] Prevent docker access when running AOT processing on tests Closes gh-37097 --- .../ServiceConnectionContextCustomizerFactory.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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"); + } + }